I want to style the output of table()
. Suppose I have the following:
dat$a <- c(1,2,3,4,4,3,4,2,2,2)
dat$b <- c(1,2,3,4,1,2,4,3,2,2)
table(dat$a,dat$b)
1 2 3 4
1 50 0 0 0
2 0 150 50 0
3 0 50 50 0
4 50 0 0 100
There are two problems with this. First, it doesn't give me the correct frequencies. Additionally, it has no row or column labels. I found this, and the table works for both frequency counts and axis labels. Is there an issue because this way subsets from a data frame? I would appreciate any tips on both fixing the frequency counts and adding style to the table.
nrow(dat)
do you have? – Khashaawith(dat,table(a,b))
ortable(a=dat$a,b=dat$b)
ortable(dat[,c("a","b")])
. I don't know why your frequencies are off. For the example you give, the frequencies should be only 1/50th of the counts you're showing. – Frankdat
is likely a 500 row data frame, which has been filled via recycling. – Christable(dat[,c("a","b")])
but still didn't get any labels. If it makes a difference, I'm running this in shiny using renderTable. – Kira Tebbe