Give row names to table in R

泄露秘密 提交于 2019-12-06 11:56:20

You can create a matrix based on the table and assign row names to it.

# an example vector
x <- c(1:5, 1:3, 4:6)

a <- table(x)

mat <- rbind(as.numeric(names(a)), a)
rownames(mat) <- c("Faces", "Count")
mat
#       1 2 3 4 5 6
# Faces 1 2 3 4 5 6
# Count 2 2 2 2 2 1

I suppose something like that would work :

t(data.frame(Faces=names(a),Counts=as.vector(a)))

Also you can keep a as it is, names(a) gives you the faces and a the corresponding counts...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!