I am trying to mutate a factor on R ver 4.5.1 and things seems not to work out. Yes my code is running perfectly well but not producing what I expect.
I 'd like to lump less frequent factors together into "other" category as follows.
df |>
mutate(
important_benefit = fct_lump(important_benefit, n = 10)
)
The output I get does not lamp the last three infrequent factor levels in to "other" category as expected (despite not giving me any warning) though it shows it has changed it from character variable to factor.
Could there be something wrong with this version of R or my code?
This problem only occurs when I am mutating after I have a group summary however when I mutate before grouping, everything works well
If you mean after group_by(...) |> summarise(...) and you grouped by multiple variables, your resulting data frame could still be grouped and you may be lumping each group individually.