Putting Labels to a table in R

table
r
format
arrange
grid

#1

I have generated the below table(frequency table) and I am getting the row names and column names. However I also need the label on the top and left side. How can we do that?

sl <- cut(Oceanair$t_ambient,breaks=c(0,44,62,78,95.5,107.5,max(Oceanair$t_ambient,na.rm=TRUE)))
table(sl)
pl <- cut(Oceanair$derate,breaks=c(0,5,15,max(Oceanair$derate,na.rm=TRUE)))
table(pl)
table(sl,pl)
a <-as.matrix(table(pl,sl))
colnames(a) <- c(“0 > 44”,“44 > 62”,“62 > 78”,“78 > 95.5”,“95.5 > 107.5”,">107.5")
rownames(a) <- c(“0 > 5”,“5 > 15”,">15")
a<-as.table(a)
a <- round(prop.table(a)*100,2)
a1 <- a
a1[] <- sprintf("%.1f%%",round(prop.table(a,1)*100, 2))
png(filename = “table.png”)
grid.table(a1)
dev.off()


#2

Hi @Surya1987

check xtabs function it will give you the variable names, the syntax is different as you have to give a formula, but the return object is more powerful as you can for example build proportional table using prop.table().

Hope this help

Alain