From 23996a081da8602888c510708e4706caeed7506d Mon Sep 17 00:00:00 2001 From: Vebash Naidoo <50318861+sciencificity@users.noreply.github.com> Date: Mon, 8 Feb 2021 18:30:40 +0200 Subject: [PATCH] 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. --- factors.Rmd | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/factors.Rmd b/factors.Rmd index 2f42a11..3fd38aa 100644 --- a/factors.Rmd +++ b/factors.Rmd @@ -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.