How would one create a two-way, sorted tabulation table in R? I have two variables. The first takes on just 4 values. The second takes on many string values. I would like to end up with a table where the columns are the 4 values and the each row is a string. The frequencies occur in the body of the table. I also want to sort this - not alphabetically by string name, but by frequency - hopefully by overall frequency, how often a word occurs (not considering the 4 categories), but I would also be happy if it were just sorted by one the frequencies in one column. Any tips on how to create this? The end goal is to create a LaTeX table.
I have this kind of data in mind.
data <- data.frame(cat = sample(1:4, 100, replace=TRUE), string = sample(c("dog", "cat", "horse", "frog", "liger", "ligon", "tigon"), 100, replace = TRUE))