Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要在多个数据子集上运行相同的模型。下面是一些模拟数据。假设我想做 3 个 t 检验,所有比较var1和var2,但每个都基于 3 个值的数据子集group。最好的方法是什么?
var1
var2
group
d <- data.frame(var1=rnorm(10), var2=rnorm(10), group=sample(c(1:3), 10, replace=TRUE))
尝试这个:
lapply(split(d,d$group), function(df) t.test(x=df$var1,y=df$var2))