-
Notifications
You must be signed in to change notification settings - Fork 2
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
table_one and summarytable sort argument: order by row option #39
Comments
Thanks for your comment! It might help if I provide a reprex. Setupusing SummaryTables, DataFrames Create the necessary columns for Race and Day of the Weekrace = vcat(fill("BLACK", 7), fill("TOM", 2), fill("WHITE", 22))
day_of_week = vcat(
# BLACK
"MON", "TUE", "TUE", "WED", "THU", "THU", "FRI",
# TOM
"FRI", "SAT",
# WHITE
"MON", "MON", "TUE", "TUE", "WED", "WED", "THU", "FRI", "FRI", "FRI",
"SAT", "SAT", "SAT", "SUN", "SUN", "MON", "TUE", "THU", "THU", "TUE",
"WED", "SAT"
) Create a DataFramefaux_data = DataFrame(RACE = race, DAY_OF_WEEK = day_of_week) Create a dictionary mapping days to their numeric order for sortingday_order = Dict("MON" => 1, "TUE" => 2, "WED" => 3, "THU" => 4, "FRI" => 5, "SAT" => 6, "SUN" => 7) Create the summary statistics using table_one --> ordering/levels do work on colsfaux_data_stats = table_one(
sort(faux_data, :DAY_OF_WEEK, by = x -> day_order[x]),
:RACE => "Race",
groupby = :DAY_OF_WEEK => "Day",
show_n = true;
sort = false
) Create the summary statistics using table_one --> ordering/levels do not work on rowsfaux_data_stats = table_one(
sort(faux_data, :DAY_OF_WEEK, by = x -> day_order[x]),
:DAY_OF_WEEK => "Day",
groupby = :RACE => "Race",
show_n = true;
sort = false
) I should have provided the reprex in the first place, sorry about that. I hope you can see what I am referring to. This seems to be expected behavior and I am suggesting it would be a great enhancement to be able to order those rows based on a Dict object or another method. Maybe I should have tried running categorical() on my day variable, instead? |
Ahh now I see, you mean the sorting within a "categorical variable" analysis. I will have to think a little about possible APIs for this (aside from making categorical values which sort as expected on their own) |
@jkrumbiegel Thanks for your time and review! I hope I have been helpful. In any case, |
Would it be possible to have an argument that a user could leverage to sort the rows as well? Presently sort kw only sorts the columns. It would likely need to be a separate kw argument.
With multiple row arguments that could be tricky, but I have a use case where it would be nice on a longer table where I wanted to display days of the week on the rows and could not order them using summarytable or table-one.
Thanks for taking time to read this!
The text was updated successfully, but these errors were encountered: