r - 按名称划分 R 表维度
问题描述
我有一个 3Dtable()
输出。如何按名称对 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?
解决方案
您想使用margin.table
或marginSums
。这两个功能是一样的。第二个更具描述性,但第一个是原始名称。要将 3 维数组折叠为 2 维:
margin.table(tbl, c("dim1", "dim2")) # Or margin.table(tbl, 1:2)
会给你一样的
table(dim1, dim2)
推荐阅读
- maven - 如何配置 Maven 以仅在部署时执行测试
- c# - 尝试将 Task.WhenAll 与 Task 一起使用
不工作 - python-3.x - 如何在没有计算机的情况下预测输出?
- javascript - 如何将 openzeppelin 升级模块集成到松露项目中,具体如何“链接”?
- python - Django 1.11:为经过身份验证的用户禁用缓存
- java - 我该如何存储
> 在 Java 中? - python - 在单独的csv行中写入json数据
- graphql - GraphQL 类型的列表是否应该总是分页?
- php - Laravel:更新表单保持当前图像而不输入新图像不起作用
- flutter - 如何从java代码中获取数据到flutter