假设我有data.table
x
:
x <- data.table(Motif = c("A","A","B","B","B","C"),
Strain = c(1,1,1,2,2,3),
IPDRatio = c(1:6))
如何通过按因子data.table
和Motif
折叠整个Strain
来找到IPDRatio列的平均值?
期望的输出:
Motif Strain IPDRatio
1: A 1 1.5
2: B 1 3
3: B 2 4.5
4: C 3 6
答案 0 :(得分:2)
这应该有效
x[, mean(IPDRatio), list(Motif, Strain)]