2 回答
TA贡献2039条经验 获得超7个赞
fun.aggregate
?dcast
):
如果变量没有标识每个输出单元格的单个观察,则需要聚合函数。默认为长度(带有消息)(如果需要但未指定)
基于您的数据的解释:
dcast(df, Id + Task ~ Type, value.var="Freq")
Id Task A B1 3 1 2 32 3 2 3 03 4 1 3 34 4 2 1 3
Id
, Task
Type
Freq
dcast(df, Id ~ Type, value.var="Freq")
Aggregation function missing: defaulting to length Id A B1 3 2 22 4 2 2
Id Task Type Freq 3 1 A 23 1 B 33 2 A 33 2 B 0
Id
Type
Freq
2
3
A
& 3
0
B
type
dcast
length
sum
, mean
, sd
fun.aggregate
.
fun.aggregate = sum
Id A B1 3 5 32 4 4 6
dcast
TA贡献1801条经验 获得超16个赞
toString
dcast(df, Id ~ Type, value.var="Freq", fun.aggregate = toString)
f.agg <- function(x) paste(x, collapse = "-")
dcast(df, Id ~ Type, value.var="Freq", fun.aggregate = f.agg)
- 2 回答
- 0 关注
- 601 浏览
添加回答
举报