Hi David, I’m running into an error when I try to use the slice_max function in the Advanced Summarizing section:
number_1819 <- enrollment_18_19 %>%
select(-contains("percent")) %>%
select(-contains("kindergarten")) %>%
select(-contains("grade")) %>%
#select(district_id, !matches("percent|kindergarten|grade")) %>% Does the same thing but shorter code
pivot_longer(cols = -district_id,
names_to = "race_ethnicity",
values_to = "number_of_students") %>%
mutate(number_of_students = na_if(number_of_students, "-")) %>%
mutate(number_of_students = replace_na(number_of_students, 0)) %>% #can replace NAs with 0 if we know the data isn't missing
mutate(number_of_students = as.numeric(number_of_students)) %>% #Change data type from character to numeric
mutate(year = "2018-19") %>%
mutate(race_ethnicity = str_remove(race_ethnicity, "x2018_19_")) %>% #Get rid of string in front of values
mutate(race_ethnicity = str_replace_all(race_ethnicity, "_", " ")) %>% #Replace _ with a space
mutate(race_ethnicity = tools::toTitleCase(tolower(race_ethnicity))) %>% #Capitalizes every word
mutate(race_ethnicity = recode(race_ethnicity,
"American Indian Alaska Native" = "American Indian/Alaska Native",
"Black African American" = "Black/African American",
"Hispanic Latino" = "Hispanic/Latinx",
"Native Hawaiian Pacific Islander" = "Native Hawaiian/Pacific Islander")) %>% #Recodes with /
mutate(number_categorical = case_when(
number_of_students == 0 ~ "None",
number_of_students < 50 ~ "Less than 50",
between(number_of_students, 50, 100) ~ "Between 50 and 100",
number_of_students > 100 ~ "Greater than 100"
)) %>%
ungroup() %>%
group_by(district_id) %>%
mutate(pct = number_of_students / sum(number_of_students)) %>% # Like a calculated column
ungroup() %>%
slice_max(pct, 1) %>% # Which district has the highest percent?
arrange(district_id, race_ethnicity)
Here is my error:
Error: ...
is not empty.
We detected these problematic arguments:
* ..1
These dots only exist to allow future extensions and should be empty.
Did you misspecify an argument?
Run rlang::last_error()
to see where the error occurred.
> rlang::last_error()
<error/rlib_error_dots_nonempty>
...
is not empty.
We detected these problematic arguments:
* ..1
These dots only exist to allow future extensions and should be empty.
Did you misspecify an argument?
Backtrace:
1. %>%
(...)
4. dplyr:::slice_max.data.frame(., pct, 1)
5. ellipsis::check_dots_empty()
6. ellipsis:::action_dots(...)