dplyr does have a drop option (#894)

We can include levels with no observations in dplyr::count() now with the .drop = FALSE argument setting. I changed the wording and added an example. Please feel free to amend text wording and remove example if you wish.
This commit is contained in:
Vebash Naidoo 2021-02-08 18:30:40 +02:00 committed by GitHub
parent d1a3741fd5
commit 23996a081d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 1 deletions

View File

@ -125,7 +125,13 @@ ggplot(gss_cat, aes(race)) +
scale_x_discrete(drop = FALSE)
```
These levels represent valid values that simply did not occur in this dataset. Unfortunately, dplyr doesn't yet have a `drop` option, but it will in the future.
These levels represent valid values that simply did not occur in this dataset. In dplyr::count() set the `.drop` option to `FALSE`, to show these.
```{r}
gss_cat %>%
count(race,
.drop = FALSE)
```
When working with factors, the two most common operations are changing the order of the levels, and changing the values of the levels. Those operations are described in the sections below.