Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.

Commit 41ba8ac

Browse files
committed
Updated dtata structures part 1 section
1 parent 8620561 commit 41ba8ac

4 files changed

+25
-24
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ _site
66
pandoc
77
ssh-keygen.txt.pub
88
ssh-keygen.txt
9+
feline-data.csv

Diff for: 04-data-structures-part1.Rmd

+8-8
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ tabby,3.2,TRUE
2929
cats.df <- data.frame(coat = c("calico", "black", "tabby"),
3030
weight = c(2.1, 5.0, 3.2),
3131
likes_string = c(TRUE, FALSE, TRUE))
32-
write.csv(cats.df, "data/feline-data.csv", row.names = FALSE)
32+
write.csv(cats.df, "feline-data.csv", row.names = FALSE)
3333
```
3434

3535
We can load this into R via the following:
3636

3737
```{r}
38-
cats <- read.csv(file = "data/feline-data.csv")
38+
cats <- read.csv(file = "feline-data.csv")
3939
cats
4040
```
4141

@@ -83,7 +83,7 @@ tabby,2.3 or 2.4,TRUE
8383
Reload your cats data like before, and check what type of data we find in the `weight` column:
8484

8585
```{r}
86-
cats <- read.csv(file="data/feline-data.csv")
86+
cats <- read.csv(file="feline-data.csv")
8787
typeof(cats$weight[1])
8888
```
8989

@@ -107,7 +107,7 @@ tabby,3.2,TRUE
107107
And back in RStudio:
108108

109109
```
110-
cats <- read.csv(file="data/feline-data.csv")
110+
cats <- read.csv(file="feline-data.csv")
111111
```
112112

113113
## Vectors & Type Coercion
@@ -186,7 +186,7 @@ Concatenate will also append things to an existing vector:
186186
```{r}
187187
ab_vector <- c('a', 'b')
188188
ab_vector
189-
concat_example <- c(ab_vector, 'SWC')
189+
concat_example <- c(ab_vector, 'RES')
190190
concat_example
191191
```
192192

@@ -220,7 +220,7 @@ names_example['b']
220220
> ## Challenge 1 {.challenge}
221221
> Start by making a vector with the numbers 11 to 20.
222222
> Then use the functions we just learned to extract the 3rd through 5th element in that vector into a new vector;
223-
> name the elements in that new vector 'S', 'W', 'C'.
223+
> name the elements in that new vector 'R', 'E', 'S'.
224224
>
225225
226226
## Factors
@@ -388,13 +388,13 @@ matrix_example
388388
> ```{r}
389389
> x <- c(11:20)
390390
> subset <- x[3:5]
391-
> names(subset) <- c('S', 'W', 'C')
391+
> names(subset) <- c('R', 'E', 'S')
392392
> ```
393393
>
394394
395395
> ## Solution to Challenge 2 {.challenge}
396396
> ```{r}
397-
> cats <- read.csv(file="data/feline-data.csv", stringsAsFactors=FALSE)
397+
> cats <- read.csv(file="feline-data.csv", stringsAsFactors=FALSE)
398398
> str(cats$coat)
399399
> ```
400400
> Note: new students find the help files difficult to understand; make sure to let them know

Diff for: 04-data-structures-part1.html

+8-8
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ <h2><span class="glyphicon glyphicon-certificate"></span>Learning Objectives</h2
4747
black,<span class="fl">5.0</span>,<span class="ot">FALSE</span>
4848
tabby,<span class="fl">3.2</span>,<span class="ot">TRUE</span></code></pre>
4949
<p>We can load this into R via the following:</p>
50-
<pre class="sourceCode r"><code class="sourceCode r">cats &lt;-<span class="st"> </span><span class="kw">read.csv</span>(<span class="dt">file =</span> <span class="st">&quot;data/feline-data.csv&quot;</span>)
50+
<pre class="sourceCode r"><code class="sourceCode r">cats &lt;-<span class="st"> </span><span class="kw">read.csv</span>(<span class="dt">file =</span> <span class="st">&quot;feline-data.csv&quot;</span>)
5151
cats</code></pre>
5252
<pre class="output"><code> coat weight likes_string
5353
1 calico 2.1 TRUE
@@ -89,7 +89,7 @@ <h2 id="data-types">Data Types</h2>
8989
<p>Note the <code>L</code> suffix to insist that a number is an integer. No matter how complicated our analyses become, all data in R is interpreted as one of these basic data types. This strictness has some really important consequences. Go back to your text editor and add add this line to feline-data.csv:</p>
9090
<pre class="sourceCode r"><code class="sourceCode r">tabby,<span class="fl">2.3</span> or <span class="fl">2.4</span>,<span class="ot">TRUE</span></code></pre>
9191
<p>Reload your cats data like before, and check what type of data we find in the <code>weight</code> column:</p>
92-
<pre class="sourceCode r"><code class="sourceCode r">cats &lt;-<span class="st"> </span><span class="kw">read.csv</span>(<span class="dt">file=</span><span class="st">&quot;data/feline-data.csv&quot;</span>)
92+
<pre class="sourceCode r"><code class="sourceCode r">cats &lt;-<span class="st"> </span><span class="kw">read.csv</span>(<span class="dt">file=</span><span class="st">&quot;feline-data.csv&quot;</span>)
9393
<span class="kw">typeof</span>(cats$weight[<span class="dv">1</span>])</code></pre>
9494
<pre class="output"><code>[1] &quot;double&quot;
9595
</code></pre>
@@ -104,7 +104,7 @@ <h2 id="data-types">Data Types</h2>
104104
black,5.0,FALSE
105105
tabby,3.2,TRUE</code></pre>
106106
<p>And back in RStudio:</p>
107-
<pre><code>cats &lt;- read.csv(file=&quot;data/feline-data.csv&quot;)</code></pre>
107+
<pre><code>cats &lt;- read.csv(file=&quot;feline-data.csv&quot;)</code></pre>
108108
<h2 id="vectors-type-coercion">Vectors &amp; Type Coercion</h2>
109109
<p>To better understand the behavior we just saw, let’s meet another of the data structures: the <em>vector</em>.</p>
110110
<pre class="sourceCode r"><code class="sourceCode r">my_vector &lt;-<span class="st"> </span><span class="kw">vector</span>(<span class="dt">length=</span><span class="dv">3</span>)
@@ -168,9 +168,9 @@ <h2><span class="glyphicon glyphicon-pencil"></span>Discussion 1</h2>
168168
ab_vector</code></pre>
169169
<pre class="output"><code>[1] &quot;a&quot; &quot;b&quot;
170170
</code></pre>
171-
<pre class="sourceCode r"><code class="sourceCode r">concat_example &lt;-<span class="st"> </span><span class="kw">c</span>(ab_vector, <span class="st">&#39;SWC&#39;</span>)
171+
<pre class="sourceCode r"><code class="sourceCode r">concat_example &lt;-<span class="st"> </span><span class="kw">c</span>(ab_vector, <span class="st">&#39;RES&#39;</span>)
172172
concat_example</code></pre>
173-
<pre class="output"><code>[1] &quot;a&quot; &quot;b&quot; &quot;SWC&quot;
173+
<pre class="output"><code>[1] &quot;a&quot; &quot;b&quot; &quot;RES&quot;
174174
</code></pre>
175175
<p>You can also make series of numbers:</p>
176176
<pre class="sourceCode r"><code class="sourceCode r">mySeries &lt;-<span class="st"> </span><span class="dv">1</span>:<span class="dv">10</span>
@@ -216,7 +216,7 @@ <h2><span class="glyphicon glyphicon-pencil"></span>Discussion 1</h2>
216216
<h2><span class="glyphicon glyphicon-pencil"></span>Challenge 1</h2>
217217
</div>
218218
<div class="panel-body">
219-
<p>Start by making a vector with the numbers 11 to 20. Then use the functions we just learned to extract the 3rd through 5th element in that vector into a new vector; name the elements in that new vector ‘S’, ‘W’, ‘C’.</p>
219+
<p>Start by making a vector with the numbers 11 to 20. Then use the functions we just learned to extract the 3rd through 5th element in that vector into a new vector; name the elements in that new vector ‘R’, ‘E’, ‘S’.</p>
220220
</div>
221221
</section>
222222
<h2 id="factors">Factors</h2>
@@ -399,15 +399,15 @@ <h2><span class="glyphicon glyphicon-pencil"></span>Solution to Challenge 1</h2>
399399
<div class="panel-body">
400400
<pre class="sourceCode r"><code class="sourceCode r">x &lt;-<span class="st"> </span><span class="kw">c</span>(<span class="dv">11</span>:<span class="dv">20</span>)
401401
subset &lt;-<span class="st"> </span>x[<span class="dv">3</span>:<span class="dv">5</span>]
402-
<span class="kw">names</span>(subset) &lt;-<span class="st"> </span><span class="kw">c</span>(<span class="st">&#39;S&#39;</span>, <span class="st">&#39;W&#39;</span>, <span class="st">&#39;C&#39;</span>)</code></pre>
402+
<span class="kw">names</span>(subset) &lt;-<span class="st"> </span><span class="kw">c</span>(<span class="st">&#39;R&#39;</span>, <span class="st">&#39;E&#39;</span>, <span class="st">&#39;S&#39;</span>)</code></pre>
403403
</div>
404404
</section>
405405
<section class="challenge panel panel-success">
406406
<div class="panel-heading">
407407
<h2><span class="glyphicon glyphicon-pencil"></span>Solution to Challenge 2</h2>
408408
</div>
409409
<div class="panel-body">
410-
<pre class="sourceCode r"><code class="sourceCode r">cats &lt;-<span class="st"> </span><span class="kw">read.csv</span>(<span class="dt">file=</span><span class="st">&quot;data/feline-data.csv&quot;</span>, <span class="dt">stringsAsFactors=</span><span class="ot">FALSE</span>)
410+
<pre class="sourceCode r"><code class="sourceCode r">cats &lt;-<span class="st"> </span><span class="kw">read.csv</span>(<span class="dt">file=</span><span class="st">&quot;feline-data.csv&quot;</span>, <span class="dt">stringsAsFactors=</span><span class="ot">FALSE</span>)
411411
<span class="kw">str</span>(cats$coat)</code></pre>
412412
<pre class="output"><code> chr [1:3] &quot;calico&quot; &quot;black&quot; &quot;tabby&quot;
413413
</code></pre>

Diff for: 04-data-structures-part1.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ We can load this into R via the following:
3030

3131

3232
~~~{.r}
33-
cats <- read.csv(file = "data/feline-data.csv")
33+
cats <- read.csv(file = "feline-data.csv")
3434
cats
3535
~~~
3636

@@ -158,7 +158,7 @@ Reload your cats data like before, and check what type of data we find in the `w
158158

159159

160160
~~~{.r}
161-
cats <- read.csv(file="data/feline-data.csv")
161+
cats <- read.csv(file="feline-data.csv")
162162
typeof(cats$weight[1])
163163
~~~
164164

@@ -197,7 +197,7 @@ tabby,3.2,TRUE
197197
And back in RStudio:
198198

199199
```
200-
cats <- read.csv(file="data/feline-data.csv")
200+
cats <- read.csv(file="feline-data.csv")
201201
```
202202

203203
## Vectors & Type Coercion
@@ -382,14 +382,14 @@ ab_vector
382382

383383

384384
~~~{.r}
385-
concat_example <- c(ab_vector, 'SWC')
385+
concat_example <- c(ab_vector, 'RES')
386386
concat_example
387387
~~~
388388

389389

390390

391391
~~~{.output}
392-
[1] "a" "b" "SWC"
392+
[1] "a" "b" "RES"
393393
394394
~~~
395395

@@ -515,7 +515,7 @@ b
515515
> ## Challenge 1 {.challenge}
516516
> Start by making a vector with the numbers 11 to 20.
517517
> Then use the functions we just learned to extract the 3rd through 5th element in that vector into a new vector;
518-
> name the elements in that new vector 'S', 'W', 'C'.
518+
> name the elements in that new vector 'R', 'E', 'S'.
519519
>
520520
521521
## Factors
@@ -893,14 +893,14 @@ matrix_example
893893
> ~~~{.r}
894894
> x <- c(11:20)
895895
> subset <- x[3:5]
896-
> names(subset) <- c('S', 'W', 'C')
896+
> names(subset) <- c('R', 'E', 'S')
897897
> ~~~
898898
>
899899
900900
> ## Solution to Challenge 2 {.challenge}
901901
>
902902
> ~~~{.r}
903-
> cats <- read.csv(file="data/feline-data.csv", stringsAsFactors=FALSE)
903+
> cats <- read.csv(file="feline-data.csv", stringsAsFactors=FALSE)
904904
> str(cats$coat)
905905
> ~~~
906906
>

0 commit comments

Comments
 (0)