我有3个数据集,希望对所有数据运行相同的线性模型,存储系数及其置信上限和下限.
set.seed(1)
school1 = data.frame(student = sample(c(1:100), 100, r = T),
score = runif(100))
school2 = data.frame(student = sample(c(1:100), 100, r = T),
score = runif(100))
school3 = data.frame(student = sample(c(1:100), 100, r = T),
score = runif(100))
schools = list('school1', 'school2', 'school3')
storage <- vector('list', length(schools))
for(i in seq_along(schools)){
tmpdat <- schools[[i]]
tmp <- lm(score ~ x1, data = tmpdat)
storage[[i]] <- summary(tmp)$coef[1]
}
我希望生成存储所有信息以及数据集名称的WANT:
WANT = data.frame(data = c('school1', 'school2', 'school3'),
coef = c(0,0,0),
coefLL = c(0,0,0),
coefUL=c(0,0,0))
但我在苦苦挣扎,我遍历了数据集,但不知道如何存储我需要的所有信息……还有,我有大约1000个数据集,所以最有效的方法是最好的,非常感谢