【发布时间】:2021-12-11 01:01:39
【问题描述】:
我在 R 中有下表:
我想做的是将一些教育程度值组合在一起:
1) group 102-111 --> less than 9th grade
2) group 113-116 --> 9-12th grade no hs degree
3) 201 --> high school diploma
4) 301 --> some college no degree
5) 302-303 --> associate degree
6) 400 --> bachelor degree
7) 501 --> master degree
8) 502 --> professional degree
9) 503 --> doctorate degree (PhD)
我该怎么做呢?谢谢
dput R 输出:
structure(c(99, 500, 31, 44, 64, 68, 100, 312, 147, 405, 444,
514, 692, 624, 7055, 986, 6260, 2235, 1761, 6732, 3212, 439,
581, 33305, 39, 207, 10, 21, 28, 18, 33, 120, 51, 178, 211, 267,
320, 214, 2088, 487, 2071, 636, 477, 1213, 493, 71, 76, 9329,
65, 402, 14, 28, 50, 27, 45, 151, 79, 209, 316, 367, 437, 354,
4340, 748, 4186, 1440, 1155, 3824, 1671, 253, 303, 20464, 203,
1109, 55, 93, 142, 113, 178, 583, 277, 792, 971, 1148, 1449,
1192, 13483, 2221, 12517, 4311, 3393, 11769, 5376, 763, 960,
63098), .Dim = c(24L, 4L), .Dimnames = list(EDUC = c("102", "103",
"104", "105", "106", "107", "108", "109", "110", "111", "113",
"114", "115", "116", "201", "202", "301", "302", "303", "400",
"501", "502", "503", "Sum"), DEPFEELEVL = c("1", "2", "3", "Sum"
)), class = c("table", "matrix", "array"))
想要对相似的元素进行分组而不只是重命名:
DEPFEELEVL
EDUC 1 2 3 Sum
less than 9th grade 99 39 65 203
less than 9th grade 500 207 402 1109
less than 9th grade 31 10 14 55
less than 9th grade 44 21 28 93
less than 9th grade 64 28 50 142
less than 9th grade 68 18 27 113
less than 9th grade 100 33 45 178
less than 9th grade 312 120 151 583
less than 9th grade 147 51 79 277
less than 9th grade 405 178 209 792
9-12th grade no hs degree 444 211 316 971
9-12th grade no hs degree 514 267 367 1148
9-12th grade no hs degree 692 320 437 1449
9-12th grade no hs degree 624 214 354 1192
high school diploma 7055 2088 4340 13483
doctorate degree (PhD) 986 487 748 2221
some college no degree 6260 2071 4186 12517
doctorate degree (PhD) 2235 636 1440 4311
doctorate degree (PhD) 1761 477 1155 3393
bachelor degree 6732 1213 3824 11769
master degree 3212 493 1671 5376
professional degree 439 71 253 763
doctorate degree (PhD) 581 76 303 960
Sum 33305 9329 20464 63098
因此,例如,让我们考虑受教育程度为 9-12 年级的受访者,为简单起见,考虑抑郁症 1 级。
表格应该显示
444+514+692+624 = 2274
对于我用作示例的特定单元格
【问题讨论】:
-
是的,我真的不能这样做,因为数据来自 IPUMS,即使我清理了它,我也有 63098 个数据点,并且大部分 dput() 函数都没有显示在控制台中,因为它是如此大
-
该链接无效吗?我也会放原始数据,但我没有足够的信誉使它看起来像一张完整的图片
-
哦,我看到我粘贴了表格数据,不确定是否有帮助
-
使用 dput(addmargins(table1)) 并发布 R 返回的内容。这样其他人就可以复制粘贴您的表格。
-
是的,这是一回事。见here
标签: r