From d071a1a45ce7b65c7cc3d96f5473981d72d9a647 Mon Sep 17 00:00:00 2001 From: hadley Date: Thu, 18 Aug 2016 09:38:33 -0500 Subject: [PATCH] Use tibble instead of data.frame --- iteration.Rmd | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/iteration.Rmd b/iteration.Rmd index 5f9b398..6c5dcfd 100644 --- a/iteration.Rmd +++ b/iteration.Rmd @@ -32,7 +32,7 @@ library(purrr) Imagine we have this simple data frame: ```{r} -df <- data.frame( +df <- tibble::tibble( a = rnorm(10), b = rnorm(10), c = rnorm(10), @@ -170,7 +170,7 @@ There are four variations on the basic theme of the for loop: Sometimes you want to use a for loop to modify an existing object. For example, remember our challenge from [functions]. We wanted to rescale every column in a data frame: ```{r} -df <- data.frame( +df <- tibble::tibble( a = rnorm(10), b = rnorm(10), c = rnorm(10), @@ -369,7 +369,7 @@ For loops are not as important in R as they are in other languages because R is To see why this is important, consider (again) this simple data frame: ```{r} -df <- data.frame( +df <- tibble::tibble( a = rnorm(10), b = rnorm(10), c = rnorm(10), @@ -941,7 +941,11 @@ x %>% accumulate(`+`) But it has a number of bugs as illustrated with the following inputs: ```{r, eval = FALSE} - df <- data.frame(z = c("a", "b", "c"), x = 1:3, y = 3:1) + df <- tibble::tibble( + x = 1:3, + y = 3:1, + z = c("a", "b", "c") + ) # OK col_sum3(df, mean) # Has problems: don't always return numeric vector