给定的数据是:
farmer<-c("F1","F2","F3","F4","F5","F6")
animal<-c("A1","A2","A3","A4","A5","A6","A7","A8")
time<-c("T1","T2","T3","T4","T5")
disease<-c("ww","ee","dd","ss","kk","ll","xx","oo","hh")
sample(farmer,size=100,replace = TRUE)
df<-data.frame(farmer=sample(farmer,size=100,replace = TRUE),
animal=sample(animal,size=100,replace = TRUE),
time=sample(time,size=100,replace = TRUE),
disease=sample(disease,size=100,replace = TRUE))
head(df)
问题:在特定时间和特定动物患有相同疾病的农民人数?
输出应如下所示:
答案 0 :(得分:0)
library(data.table)
dt <- setDT(df)
dt[, .(NumberOfFarmers = .N), by = .(animal, time, disease)]
我想这应该是您要寻找的东西。