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

Add Descriptive Name To First Column Of Tabyl And Sort N Descending #488

Closed
gfleetwood opened this issue Sep 8, 2022 · 5 comments
Closed

Comments

@gfleetwood
Copy link

This is a feature request for the tabyl function. Having a dot for a column name is awkward, especially if it becomes part of another workflow. I usually rename it to unique_values.

Sorting n descending is just something else that came to mind that I often end up doing as well.

@sfirke
Copy link
Owner

sfirke commented Sep 19, 2022

What command are you using that gives you a dot for a column name?

The sorting has been discussed before and was actually in an early version of tabyl but was removed. I suggest piping to %>% arrange(desc(n)) after loading dplyr.

@gfleetwood
Copy link
Author

gfleetwood commented Sep 19, 2022

That's what I've been doing for the sorting. As for the column name, I'm on Ubuntu 20.04 using R 4.2.1 and janitor 2.1.0:

library(tidyverse)

iris %>% 
  pull(Species) %>% 
  janitor::tabyl()
#>           .  n   percent
#>      setosa 50 0.3333333
#>  versicolor 50 0.3333333
#>   virginica 50 0.3333333

Created on 2022-09-19 by the reprex package (v2.0.1)

@sfirke
Copy link
Owner

sfirke commented Sep 19, 2022

Ah, the pull gives you an unnamed vector, no way to know what that input should be named. Try instead simply:

iris %>% tabyl(Species)
    Species  n   percent
     setosa 50 0.3333333
 versicolor 50 0.3333333
  virginica 50 0.3333333

@sfirke sfirke closed this as completed Sep 19, 2022
@sfirke
Copy link
Owner

sfirke commented Sep 19, 2022

Or tabyl(iris$Species)

@gfleetwood
Copy link
Author

Got it. Thanks.

@sfirke sfirke changed the title Add Descriptive Name To First Column Of Tably And Sort N Descending Add Descriptive Name To First Column Of Tabyl And Sort N Descending Sep 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants