Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从R中的数据框创建嵌套表_R - Fatal编程技术网

从R中的数据框创建嵌套表

从R中的数据框创建嵌套表,r,R,我有一个数据框,一个可复制的例子是: 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

我有一个数据框,一个可复制的例子是:

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

我试着使用重塑2重铸函数…但它用我不想要的NA值填充表格。任何想法都会很有帮助。

你想这样做吗?您可以尝试
split(data,data$Events)
c列在哪里?这正是我需要的….:-)非常感谢。@akrun我没有包括c…只是觉得有点懒…@NicE现在不存在这个。你能回答一下吗?这样我就可以投票了。只需显示代码和您希望显示的内容的返回,它将涵盖一个好答案所需的内容。您想吗?您可以尝试
split(data,data$Events)
c列在哪里?这正是我需要的….:-)非常感谢。@akrun我没有包括c…只是觉得有点懒…@NicE现在不存在这个。你能回答一下吗?这样我就可以投票了。只需显示代码和您希望显示的内容的返回,它将涵盖一个好答案所必需的内容。