This is the final practice of data frame formats. Now you should be familiar with the three main ones: data.frame, data.table, and tibble. Repeat the practice tasks for tibbles now using the data.table format instead. This exercise does not count toward your grade. It is just for practice!
Exercises
-
How can you tell if an object is a tibble? (Hint: try printing
mtcars
, which is a regular data frame). -
Compare and contrast the following operations on a
data.frame
and equivalent tibble. What is different? Why might the default data frame behaviours cause you frustration?df <- data.frame(abc = 1, xyz = "a") df$x df[, "xyz"] df[, c("abc", "xyz")]
-
If you have the name of a variable stored in an object, e.g.
var <- "mpg"
, how can you extract the reference variable from a tibble? -
Practice referring to non-syntactic names in the following data frame by:
-
Extracting the variable called
1
. -
Plotting a scatterplot of
1
vs2
. -
Creating a new column called
3
which is2
divided by1
. -
Renaming the columns to
one
,two
andthree
.
annoying <- tibble( `1` = 1:10, `2` = `1` * 2 + rnorm(length(`1`)) )
-
-
What does
tibble::enframe()
do? When might you use it? -
What option controls how many additional column names are printed at the footer of a tibble?
Source: H. Wickham and G. Grolemund, https://r4ds.had.co.nz/tibbles.html This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 3.0 License.