Skip to content

Commit

Permalink
Render site
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jun 11, 2024
1 parent c591c95 commit 4dd6b51
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 61 deletions.
8 changes: 4 additions & 4 deletions help.html
Original file line number Diff line number Diff line change
Expand Up @@ -405,16 +405,16 @@ <h2><strong>Why are my changes not taking effect? It’s making my results
<p>Here we are creating a new object from an existing one:</p>
<pre class="r"><code>new_rivers &lt;- sample(rivers, 5)
new_rivers</code></pre>
<pre><code>## [1] 338 255 500 760 233</code></pre>
<pre><code>## [1] 524 280 500 444 780</code></pre>
<p>Using just this will only print the result and not actually change
<code>new_rivers</code>:</p>
<pre class="r"><code>new_rivers + 1</code></pre>
<pre><code>## [1] 339 256 501 761 234</code></pre>
<pre><code>## [1] 525 281 501 445 781</code></pre>
<p>If we want to modify <code>new_rivers</code> and save that modified
version, then we need to reassign <code>new_rivers</code> like so:</p>
<pre class="r"><code>new_rivers &lt;- new_rivers + 1
new_rivers</code></pre>
<pre><code>## [1] 339 256 501 761 234</code></pre>
<pre><code>## [1] 525 281 501 445 781</code></pre>
<p>If we forget to reassign this can cause subsequent steps to not work
as expected because we will not be working with the data that has been
modified.</p>
Expand Down Expand Up @@ -484,7 +484,7 @@ <h2><strong>Error: object ‘X’ not found</strong></h2>
operator:</p>
<pre class="r"><code>rivers2 &lt;- new_rivers + 1
rivers2</code></pre>
<pre><code>## [1] 340 257 502 762 235</code></pre>
<pre><code>## [1] 526 282 502 446 782</code></pre>
<hr />
</div>
<div id="error-unexpected-in-error-unexpected-in-error-unexpected-x-in"
Expand Down
118 changes: 61 additions & 57 deletions modules/Data_Input/lab/Data_Input_Lab.html
Original file line number Diff line number Diff line change
Expand Up @@ -353,70 +353,91 @@ <h1 class="title toc-ignore">Data Input Lab</h1>
</div>


<div id="helpful-tips-before-we-start" class="section level2">
<h2>Helpful tips before we start</h2>
<div id="troubleshooting-common-new-user-mistakes-we-have-seen" class="section level3">
<h3>TROUBLESHOOTING: Common new user mistakes we have seen</h3>
<ul>
<li>Check the file path – is the file there?<br />
</li>
<li>Typos (R is <strong>case sensitive</strong>, <code>x</code> and
<code>X</code> are different)<br />
</li>
<li>Open ended quotes, parentheses, and brackets<br />
</li>
<li>Deleting part of the code chunk<br />
</li>
<li>For any function, you can write <code>?FUNCTION_NAME</code>, or
<code>help(&quot;FUNCTION_NAME&quot;)</code> to look at the help file</li>
</ul>
</div>
<div id="r-projects" class="section level3">
<h3>R Projects</h3>
<p>R Projects can help you keep files organized and avoid issues with
working directories. Check out our resource here: <a href="https://jhudatascience.org/intro_to_r/resources/R_Projects.html" class="uri">https://jhudatascience.org/intro_to_r/resources/R_Projects.html</a></p>
</div>
</div>
<div id="lab" class="section level2">
<h2>Lab</h2>
<p>In this lab you can use the interactive console to explore or
<strong>Knit</strong> the document. Remember anything you type here can
be “sent” to the console with Cmd-Enter (OS-X) or Ctrl-Enter
(Windows/Linux) in an R code chunk.</p>
<pre class="r"><code>library(readr)</code></pre>
<div id="part-1" class="section level1">
<h1>Part 1</h1>
<pre class="r"><code># Load the necessary package
library(readr)</code></pre>
<div id="section" class="section level3">
<h3>1.1</h3>
<p>Set up your R Project. Once complete, confirm you have created a
project folder.</p>
<ul>
<li>First, save your files.</li>
<li>Click on the R Project button (blue box with a green plus sign on
the top left).</li>
<li>If prompted, don’t save your .Rdata</li>
<li>Click “New Directory”</li>
<li>Click “New Project”</li>
<li>Name the Directory (folder) and select an appropriate location (such
as Desktop)</li>
</ul>
</div>
<div id="section-1" class="section level3">
<h3>1.2</h3>
<p>Use the manual import method (File &gt; Import Dataset &gt; From Text
(<code>readr</code>)) to Read in SARS-CoV-2 vaccination data from this
URL:</p>
<p><a href="https://jhudatascience.org/intro_to_r/data/vaccinations.csv" class="uri">https://jhudatascience.org/intro_to_r/data/vaccinations.csv</a>.</p>
<p>You can learn more about how the data was collected here: <a href="https://data.cdc.gov/Vaccinations/COVID-19-Vaccinations-in-the-United-States-Jurisdi/unsk-b7fc" class="uri">https://data.cdc.gov/Vaccinations/COVID-19-Vaccinations-in-the-United-States-Jurisdi/unsk-b7fc</a></p>
</div>
<div id="section-2" class="section level3">
<h3>1.3</h3>
<div id="section-1" class="section level3">
<h3>1.2</h3>
<p>What is the dataset object called? You can find this information in
the Console or the Environment. Enter your answer as a comment using
<code>#</code>.</p>
</div>
<div id="section-3" class="section level3">
<h3>1.4</h3>
<div id="section-2" class="section level3">
<h3>1.3</h3>
<p>Preview the data by clicking the table button in the Environment. How
many observations and variables are there? Enter your answer as a
comment using <code>#</code>.</p>
</div>
</div>
<div id="part-2" class="section level1">
<h1>Part 2</h1>
<div id="section-4" class="section level3">
<h3>2.1</h3>
<div id="section-3" class="section level3">
<h3>1.4</h3>
<p>Read in SARS-CoV-2 vaccination data from URL <a href="https://jhudatascience.org/intro_to_r/data/vaccinations.csv" class="uri">https://jhudatascience.org/intro_to_r/data/vaccinations.csv</a>
and assign it to an object named <code>vacc</code>. Use the code
structure below.</p>
<pre><code># General format
library(readr)
# OBJECT &lt;- read_csv(FILE)</code></pre>
</div>
<div id="section-4" class="section level3">
<h3>1.5</h3>
<p>Take a look at the data. Do these data objects
(<code>vaccinations</code> and <code>vacc</code>) appear to be the same?
Why or why not?</p>
</div>
<div id="section-5" class="section level3">
<h3>2.2</h3>
<h3>1.6</h3>
<p>Learn your working directory by running <code>getwd()</code>. This is
where R will look for files unless you tell it otherwise.</p>
</div>
</div>
<div id="practice-on-your-own" class="section level1">
<h1>Practice on Your Own!</h1>
<div id="p.1" class="section level3">
<h3>P.1</h3>
<p>Load the <code>readxl</code> package with the <code>library()</code>
command.</p>
<p>If it is not installed, install it via:
<code>RStudio --&gt; Tools --&gt; Install Packages</code>. You can also
try <code>install.packages(&quot;readxl&quot;)</code>.</p>
</div>
<div id="section-6" class="section level3">
<h3>2.3</h3>
<div id="p.2" class="section level3">
<h3>P.2</h3>
<p>Download the dataset of asthma prevalence in the USA from: <a href="https://jhudatascience.org/intro_to_r/data/asthma.xlsx" class="uri">https://jhudatascience.org/intro_to_r/data/asthma.xlsx</a>
file to <code>asthma.xlsx</code> by running the following code chunk.
This only downloads the file, it does NOT bring the file into R.</p>
Expand All @@ -427,19 +448,16 @@ <h3>2.3</h3>
mode = &quot;wb&quot;
)</code></pre>
<p>Note: the “wb” option makes sure the file can be read correctly on
Windows machines.</p>
Windows and Apple machines.</p>
</div>
<div id="section-7" class="section level3">
<h3>2.4</h3>
<div id="p.3" class="section level3">
<h3>P.3</h3>
<p>Use the <code>read_excel()</code> function in the <code>readxl</code>
package to read the <code>asthma.xlsx</code> file and call the output
<code>asthma</code>.</p>
</div>
</div>
<div id="practice-on-your-own" class="section level1">
<h1>Practice on Your Own!</h1>
<div id="p.1" class="section level3">
<h3>P.1</h3>
<div id="p.4" class="section level3">
<h3>P.4</h3>
<p>Run the following code - is there a problem? How do you know?</p>
<pre class="r"><code>yts &lt;- read_delim(&quot;https://jhudatascience.org/intro_to_r/data/Youth_Tobacco_Survey_YTS_Data.csv&quot;, delim = &quot;\t&quot;)</code></pre>
<pre><code>## Rows: 9794 Columns: 1
Expand Down Expand Up @@ -467,32 +485,18 @@ <h3>P.1</h3>
## # ℹ abbreviated name:
## # ¹​`YEAR,LocationAbbr,LocationDesc,TopicType,TopicDesc,MeasureDesc,DataSource,Response,Data_Value_Unit,Data_Value_Type,Data_Value,Data_Value_Footnote_Symbol,Data_Value_Footnote,Data_Value_Std_Err,Low_Confidence_Limit,High_Confidence_Limit,Sample_Size,Gender,Race,Age,Education,GeoLocation,TopicTypeId,TopicId,MeasureId,StratificationID1,StratificationID2,StratificationID3,StratificationID4,SubMeasureID,DisplayOrder`</code></pre>
</div>
<div id="p.2" class="section level3">
<h3>P.2</h3>
<div id="p.5" class="section level3">
<h3>P.5</h3>
<p>By default, R reads the first sheet of an excel file. Copy your code
from question 2.4 and add the following argument:
from question P.3 and add the following argument:
<code>sheet = 2</code>. Inspect the data using <code>head()</code>.</p>
</div>
<div id="p.3" class="section level3">
<h3>P.3</h3>
<div id="p.6" class="section level3">
<h3>P.6</h3>
<p>Install and load the <code>haven</code> package. Look at the help
page for <code>read_dta()</code> function, and scroll to the very bottom
of the page. Try running some of the examples provided.</p>
</div>
<div id="p.4" class="section level3">
<h3>P.4</h3>
<p>Learn your working directory by running <code>getwd()</code></p>
<p>Create a folder in your R project called data. Move the “asthma.xlsx”
file there.</p>
<p>Modify the following code so that it finds “asthma.xlsx” in the
“data” directory.</p>
<pre><code>asthma &lt;- read_excel(path = &quot;asthma.xlsx&quot;)</code></pre>
</div>
<div id="p.5" class="section level3">
<h3>P.5</h3>
<p>Practice importing a dataset of your choice, give it an object name,
and use <code>head()</code> to preview the first few lines.</p>
</div>
</div>


Expand Down

0 comments on commit 4dd6b51

Please sign in to comment.