Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variant of fct_relabel with group sizes #263

Open
jl5000 opened this issue May 7, 2020 · 3 comments
Open

Variant of fct_relabel with group sizes #263

jl5000 opened this issue May 7, 2020 · 3 comments
Labels
feature a feature request or enhancement

Comments

@jl5000
Copy link

jl5000 commented May 7, 2020

Would it be useful to include a function which quickly modifies factor values with information about how many rows take that value? e.g.

fac <- factor(c("A","A","B","C","C","C"))
with levels A B C

fct_relabel_with_counts(fac)
with levels 'A (n=2)' 'B (n=1)' 'C (n=3)'

This would be useful for including on plots. I'm sure this would get used a lot.

@hadley hadley added the feature a feature request or enhancement label Dec 9, 2020
@hadley
Copy link
Member

hadley commented Dec 9, 2020

This feels a little too specialised to me, but maybe fct_relabel() could also supply the length of the factor as an additional second argument. Then you could do:

x %>% fct_relabel(~ paste(.x, "(n=", .y, ")"))

@jl5000
Copy link
Author

jl5000 commented Dec 9, 2020

That's probably a better solution.

@hadley
Copy link
Member

hadley commented May 18, 2022

Related to #257

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants