我有一个数据框,一个可重复的例子是:
structure(list(Events = c("a", "a", "a", "b", "b", "b", "c",
"c", "c", "c"), Locations = c("Loca1", "Loca2", "Loca3", "Loca4",
"Loca5", "Loca6", "Loca7", "Loca8", "Loca9", "Loca10"), Coll = c(78115.68,
58361.86, 37409.54, 228922.82, 192700.77, 121201.98, 53941.03,
53065.56, 46271.9, 211083.11)), .Names = c("Events", "Locations",
"Coll"), class = "data.frame", row.names = c(NA, 10L))
看起来像这样:
Events Locations Coll
1 a Loca1 78115.68
2 a Loca2 58361.86
3 a Loca3 37409.54
4 b Loca4 228922.82
5 b Loca5 192700.77
6 b Loca6 121201.98
7 c Loca7 53941.03
8 c Loca8 53065.56
9 c Loca9 46271.90
10 c Loca10 211083.11
我正在尝试创建一个嵌套的摘要表,我希望将事件作为列和位置,将Coll值作为行。我的预期输出是:
a b
Locations Coll Locations Coll
Loca1 78115.68 Loca4 228922.82
Loca2 58361.86 Loca5 192700.77
Loca3 37409.54 Loca6 121201.98
我尝试使用reshape2重铸功能......但是它填充了我不想要的NA值。任何想法都会非常有用。