R table()函数;如何获得列名?

时间:2015-06-23 23:58:10

标签: r

假设我的数据帧为df $ Cat,df $ IsYellow。两列都可以是"是"或"否"

如何生成2x2表格并在表格上打印Cat和IsYellow,以便我知道表格的哪一侧属于Cat,哪一侧属于IsYellow?

1 个答案:

答案 0 :(得分:2)

df <- data.frame(Cat=sample(c('Yes', 'No'), size=10, replace=TRUE),
                 IsYellow=sample(c('Yes', 'No'), size=10, replace=TRUE))
table(df)
##      IsYellow
## Cat   No Yes
##   No   3   1
##   Yes  2   4
相关问题