plyr
、、関数および/またはreshape2
を使用してこれをよりエレガントに行う方法は?aggregate
data.table
library(plyr)
set.seed(1)
x <- data.frame(Ind = paste0("Ind", 1:10), Treatment = c(rep("Treat",10),rep("Cont",10)),
value = rnorm(20,60,8))
tr <- subset(x, Treatment == "Treat")
tr <- rename(tr, c("value" = "Treat"))
ct <- subset(x, Treatment == "Cont")
ct <- rename(ct, c("value" = "Cont"))
merge(ct[-2], tr[-2], by = "Ind", all = T, sort = F)
# Do not run, data.frame:
Ind Cont Treat
1 Ind1 72.09425 54.98837
2 Ind2 63.11875 61.46915
3 Ind3 55.03008 53.31497
4 Ind4 42.28240 72.76225
5 Ind5 68.99945 62.63606
6 Ind6 59.64053 53.43625
7 Ind7 59.87048 63.89943
8 Ind8 67.55069 65.90660
9 Ind9 66.56977 64.60625
10 Ind10 64.75121 57.55689