【发布时间】:2016-05-18 20:51:54
【问题描述】:
我的数据框如下
TreeID Species PlotNo Basalarea
12345 A 1 120
13242 B 7 310
14567 D 8 250
13245 B 1 305
13426 B 1 307
13289 A 3 118
我用过
newdata<- aggregate(Basalarea~PlotNo+Species, data, sum, na.rm=TRUE)
聚合所有的值使得
newdata
Species PlotNo Basalarea
A 1 120
A 3 118
B 1 some value
B 7 310
D 8 250
这很好,但我想要一个这样的数据框
PlotNo A B D
1 120 some value 0
3 118 0 0
7 0 310 0
8 0 0 250
如何获取上述dataframe?
【问题讨论】:
-
请显示reproducible example 的数据以及您对解决方案的尝试。 SO 成员是帮助解决编程问题的志愿者。
-
感谢您的建议。我提供了一个我想要获得的例子。希望有人帮助我!
标签: r aggregate-functions