-
Notifications
You must be signed in to change notification settings - Fork 130
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
Provide sort argument to tabyl() #406
Comments
It's funny, back when one-way tabyl was a separate function it had a I could be convinced, I do like |
My two cents - I find that it's much simpler to just use |
If it makes any difference, here's the context on why I want this. I'm trying to teach exploration of categorical variables to some fairly new R users, and I want to end up with something like library(dplyr)
mtcars %>%
count(carb, sort = TRUE) %>%
mutate(percent = 100 * n / sum(n)) So it's just the 1-way case, but it means I have to explain a lot of subtleties like "where did that I was hoping to use library(dplyr)
library(janitor)
mtcars %>%
tabyl(carb) %>%
arrange(desc(n)) Since I'm optimizing for code that requires minimal explaining, it seems like library(janitor)
mtcars %>%
tabyl(carb, sort = TRUE) or possibly library(janitor)
mtcars %>%
tabyl(carb, sort_dim = 1) would work really nicely. |
Please add back in, or fix sorting:
The only way aroud this I've found is to used Apologies if I've failed to read something I should have read before posting. |
@pstils is your example a two-way tabyl, like |
@pstils I just pushed an update to the main branch that I think will address what you're talking about. See if your example above now works after you install the dev version from GitHub? Example:
|
@richierocks sorry for the slow response and for this getting away from what you brought up. I don't plan to re-implement a |
@sfirke Thanks Sam, despite my non-reprex that was exactly the situation. I've got the dev version and it works exactly as indended with |
In the same way that
dplyr::count()
has asort
argument, which sorts the results in descending order of count, it would be helpful iftabyl()
had an equivalentsort
argument.In the 1-dimensional case, the behavior is fairly straightforward.
would be equivalent to
For two dimensions, it's a little trickier. I think the best behavior is to only sort on the first dimension. That is,
would be equivalent to
You might want to allow the user to choose which dimension to sort on. For example, setting
sort_dim = 1
would give the previous behavior, andsort_dim = 2
would sort the column order by decreasing column sums, andsort_dim = NA
would be the default of no sorting. I'm not sure if that is too complicated an interface though.The text was updated successfully, but these errors were encountered: