我有一个3D table()输出。如何按名称对2D表进行子集?
dim1 <- LETTERS
dim2 <- letters
dim3 <- 1:26
tbl <- table(dim1, dim2, dim3)
names(attr(tbl, "dimnames")) # dim1, dim2 dim3
table(dim1, dim2) # how do I get this output without redoing the tabulation?发布于 2020-11-23 04:49:21
您希望使用margin.table或marginSums。这两种功能是相同的。第二个是描述性的,但第一个是原来的名字。若要将三维数组折叠为二维,请执行以下操作:
margin.table(tbl, c("dim1", "dim2")) # Or margin.table(tbl, 1:2)会给你同样的
table(dim1, dim2)https://stackoverflow.com/questions/64961404
复制相似问题