Suppose I have a 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))
How would I find the mean of the IPDRatio column by collapsing the entire data.table
by factors Motif
and Strain
?
Desired output:
Motif Strain IPDRatio
1: A 1 1.5
2: B 1 3
3: B 2 4.5
4: C 3 6
这应该工作
x[, mean(IPDRatio), list(Motif, Strain)]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.