Reputation: 81
Are there any table1 users that know how to sort a table descending by frequency? Example in the table attached do you know how to sort to 14,11,7?
library(table1)
mtcars$cyl <- as.factor(mtcars$cyl)
table1(~mtcars$cyl, data = mtcars)
Upvotes: 3
Views: 953
Reputation: 389175
One way would be to arrange the factor levels based on frequency of cyl
.
mtcars$cyl <- factor(mtcars$cyl, levels = as.integer(names(sort(table(mtcars$cyl),
decreasing = TRUE))))
table1::table1(~cyl, data = mtcars)
Upvotes: 4