slice_max error

  • slice_max error

     jordan.trachtenberg updated 1 month ago 2Members · 4 Posts
  • jordan.trachtenberg

    Member
    December 17, 2020 at 7:30 am

    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(...)
  • jordan.trachtenberg

    Member
    December 17, 2020 at 7:32 am

    I’ve tried reinstalling dplyr following these instructions, and it didn’t work: https://stackoverflow.com/questions/60021210/dplyr-select-is-claiming-that-i-have-extra-arguments-that-are-not-there

    And then I tried removing and reinstalling it the normal way, and ended up having to delete something called vctrs. That also didn’t work.

  • David

    Organizer
    December 17, 2020 at 12:14 pm

    Can you try changing the line with slice_max() to this and let me know if it works?

    slice_max(order_by = pct, n = 1)

  • jordan.trachtenberg

    Member
    December 17, 2020 at 12:30 pm

    That works! Thank you.

    I guess that means it didn’t recognize the arguments I had entered since I excluded the data frame. Is that correct?

Viewing 1 - 4 of 4 posts

Log in to reply.

Original Post
0 of 0 posts June 2018
Now