Replace "data frame" with "data.frame" where appropriate (#1008)

This commit is contained in:
Iain 2022-04-13 15:19:15 +01:00 committed by GitHub
parent 0786ea3c60
commit f96b374dc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -22,7 +22,7 @@ library(tidyverse)
## Creating tibbles ## Creating tibbles
Almost all of the functions that you'll use in this book produce tibbles, as tibbles are one of the unifying features of the tidyverse. Almost all of the functions that you'll use in this book produce tibbles, as tibbles are one of the unifying features of the tidyverse.
Most other R packages use regular data frames, so you might want to coerce a data frame to a tibble. Most other R packages use regular `data.frame`s, so you might want to coerce a `data.frame` to a tibble.
You can do that with `as_tibble()`: You can do that with `as_tibble()`:
```{r} ```{r}
@ -182,17 +182,17 @@ class(as.data.frame(tb))
The main reason that some older functions don't work with tibble is the `[` function. The main reason that some older functions don't work with tibble is the `[` function.
We don't use `[` much in this book because for data frames, `dplyr::filter()` and `dplyr::select()` typically allow you to solve the same problems with clearer code. We don't use `[` much in this book because for data frames, `dplyr::filter()` and `dplyr::select()` typically allow you to solve the same problems with clearer code.
With base R data frames, `[` sometimes returns a data frame, and sometimes returns a vector. With base R `data.frame`s, `[` sometimes returns a `data.frame`, and sometimes returns a vector.
With tibbles, `[` always returns another tibble. With tibbles, `[` always returns another tibble.
## Exercises ## Exercises
1. How can you tell if an object is a tibble? 1. How can you tell if an object is a tibble?
(Hint: try printing `mtcars`, which is a regular data frame). (Hint: try printing `mtcars`, which is a regular `data.frame`).
2. Compare and contrast the following operations on a `data.frame` and equivalent tibble. 2. Compare and contrast the following operations on a `data.frame` and equivalent tibble.
What is different? What is different?
Why might the default data frame behaviours cause you frustration? Why might the default `data.frame` behaviours cause you frustration?
```{r, eval = FALSE} ```{r, eval = FALSE}
df <- data.frame(abc = 1, xyz = "a") df <- data.frame(abc = 1, xyz = "a")