Skip to content

Commit c61e2a2

Browse files
Minor changes to keep the episode flow
1 parent 34e6a84 commit c61e2a2

File tree

1 file changed

+6
-26
lines changed

1 file changed

+6
-26
lines changed

episodes/04-data-structures-part1.Rmd

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,17 @@ No matter how
164164
complicated our analyses become, all data in R is interpreted as one of these
165165
basic data types. This strictness has some really important consequences.
166166

167-
A user has added details of another cat. We can add an additional row to our cats `data.frame` using `rbind`.
167+
A user has provided details of another cat. We can add an additional row to our cats table using `rbind()`.
168168

169169
```{r}
170170
additional_cat <- data.frame(coat = "tabby", weight = "2.3 or 2.4", likes_catnip = 1)
171+
additional_cat
171172
cats2 <- rbind(cats, additional_cat)
172173
cats2
173174
```
174175

175176
Let's check what type of data we find in the
176-
`weight` column of our new object:
177+
`weight` column of our new `cats2` object:
177178

178179
```{r}
179180
typeof(cats2$weight)
@@ -187,10 +188,10 @@ cats2$weight + 2
187188
```
188189

189190
What happened?
190-
The `cats` data we are working with is something called a *data frame*. Data frames
191+
The `cats` (and `cats2`) data we are working with is something called a *data frame*. Data frames
191192
are one of the most common and versatile types of *data structures* we will work with in R.
192193
A given column in a data frame cannot be composed of different data types.
193-
In this case, R does not read everything in the data frame column `weight` as a *double*, therefore the entire
194+
In this case, R cannot store everything in the data frame column `weight` as a *double* anymore once we add the row for the additional cat (because its weight is `2.3 or 2.4`), therefore the entire
194195
column data type changes to something that is suitable for everything in the column.
195196

196197
When R reads a csv file, it reads it in as a *data frame*. Thus, when we loaded the `cats`
@@ -206,28 +207,7 @@ same number of rows. Different columns in a data frame can be made up of differe
206207
data types (this is what makes them so versatile), but everything in a given
207208
column needs to be the same type (e.g., vector, factor, or list).
208209

209-
Let's explore more about different data structures and how they behave.
210-
For now, let's remove that extra line from our cats data and reload it,
211-
while we investigate this behavior further:
212-
213-
feline-data.csv:
214-
215-
```
216-
coat,weight,likes_catnip
217-
calico,2.1,1
218-
black,5.0,0
219-
tabby,3.2,1
220-
```
221-
222-
And back in RStudio:
223-
224-
```{r, eval=FALSE}
225-
cats <- read.csv(file="data/feline-data.csv")
226-
```
227-
228-
```{r, include=FALSE}
229-
cats <- cats_orig
230-
```
210+
Let's explore more about different data structures and how they behave. For now, we will focus on our original data frame `cats` (and we can forget about `cats2` for the rest of this episode).
231211

232212
### Vectors and Type Coercion
233213

0 commit comments

Comments
 (0)