Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tidy.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -535,13 +535,13 @@ Compare and contrast the `fill` arguments to `pivot_wider()` and `complete()`.

<div class="answer">

The `values_fill` argument in `pivot_wider()` and the `fill` argument to `complete()` both set vales to replace `NA`.
The `values_fill` argument in `pivot_wider()` and the `fill` argument to `complete()` both set values to replace `NA`.
Both arguments accept named lists to set values for each column.
Additionally, the `values_fill` argument of `pivot_wider()` accepts a single value.
In `complete()`, the fill argument also sets a value to replace `NA`s but it is named list, allowing for different values for different variables.
In `complete()`, the fill argument also sets a value to replace `NA`s but it is a named list, allowing for different values for different variables.
Also, both cases replace both implicit and explicit missing values.

For example, this will fill in the missing values of the long data frame with `0` `complete()`:
For example, this will fill in the missing values of the long data frame with `0` by the `values_fill` argument of `pivot_wider()`:
```{r}
stocks <- tibble(
year = c(2015, 2015, 2015, 2015, 2016, 2016, 2016),
Expand All @@ -563,7 +563,7 @@ stocks %>%
values_fill = 0)
```

For example, this will fill in the missing values of the long data frame with `0` `complete()`:
For example, this will fill in the missing values of the long data frame with `0` by `complete()`:
```{r}
stocks %>%
complete(year, qtr, fill=list(return=0))
Expand Down