Use tibble instead of data.frame

This commit is contained in:
hadley 2016-08-18 09:38:33 -05:00
parent 9d0b91acf2
commit d071a1a45c
1 changed files with 8 additions and 4 deletions

View File

@ -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