Home > database >  How to add table headers in r
How to add table headers in r

Time:04-12

I've made this table, but I want to add headers to my table which show the categories I'm comparing. At this point I've got this:

n <- c('like', 'must-be','neutral','live-with','dislike')

t <- table(factor(d$s1q4, levels = 1:5),factor(d$s1q1, levels = 1:5))
colnames(t) <- n
rownames(t) <- n
t

but now I want to add a name for d$s1q4 and d$s1q1 and make it show up in the table.

CodePudding user response:

We may use names on the dimnames

names(dimnames(t)) <- c("s1q4", "s1q1")
  • Related