Get code working again

This commit is contained in:
Hadley Wickham 2021-04-19 09:31:38 -05:00
parent 78ab61f284
commit c88a907d4a
4 changed files with 25 additions and 1 deletions

View File

@ -4,6 +4,11 @@
`between()`
```{r}
library(tidyverse)
library(nycflights13)
```
## Logical operators
Multiple arguments to `filter()` are combined with "and": every expression must be true in order for a row to be included in the output.
@ -57,6 +62,9 @@ You'll learn how to create new variables shortly.
This makes `sum()` and `mean()` very useful: `sum(x)` gives the number of `TRUE`s in `x`, and `mean(x)` gives the proportion.
```{r}
not_cancelled <- flights %>%
filter(!is.na(dep_delay), !is.na(arr_delay))
# How many flights left before 5am? (these usually indicate delayed
# flights from the previous day)
not_cancelled %>%
@ -108,7 +116,7 @@ There's no way to list every possible function that you might use, but here's a
If you need rolling aggregates (i.e. a sum computed over a rolling window), try the RcppRoll package.
```{r}
x
x <- 1:10
cumsum(x)
cummean(x)
```

View File

@ -2,6 +2,10 @@
## Introduction
```{r}
library(tidyverse)
```
## Basics
### Missing values {#missing-values-filter}

View File

@ -1056,6 +1056,10 @@ So far you've learned how to tidy `table2`, `table4a`, and `table4b`, but not `t
To fix this problem, we'll need the `separate()` function.
You'll also learn about the complement of `separate()`: `unite()`, which you use if a single variable is spread across multiple columns.
```{r}
library(tidyr)
```
### Separate
`separate()` pulls apart one column into multiple columns, by splitting wherever a separator character appears.

View File

@ -4,6 +4,14 @@
`%in%`
```{r}
library(tidyverse)
library(nycflights13)
not_cancelled <- flights %>%
filter(!is.na(dep_delay), !is.na(arr_delay))
```
## Counts
- Counts: You've seen `n()`, which takes no arguments, and returns the size of the current group.