不久前,我进行了mice()
20 次多次插补,并使用以下方法保存了这些插补:
for (i in 1:20)
{
write.csv(complete(imp20, i), file=paste("imp", i, ".csv", sep=""))
}
现在,我想通过“性虐待”(该变量指儿童期性虐待)在所有这 20 个数据框架中推导出名为“remitted”(指精神病缓解)的变量的平均n和%。与其单独做 20 次,然后手动推导出平均值,我希望在 R 中有更简单的方法。我将不胜感激。我的一小部分数据如下所示。感谢您的帮助。
> head(df, 10)
sexabuse remitted
1 0. No 1. Yes
2 0. No 0. No
3 0. No 0. No
4 0. No 0. No
5 0. No 0. No
6 1. Yes 1. Yes
7 1. Yes 0. No
8 0. No 0. No
9 0. No 0. No
10 0. No 1. Yes
如果我正确理解你的问题(你想找到 20 个不同 data.frame 的平均值)。然后您可以执行以下操作:
df <- do.call(rbind,imp20) ##imp20 here is the 20 data.frames
write.table(df,file = "name of your file")
tablee <- read.table("name of your file")
tablee
summ_result <- apply(tablee,2,summary) ##this will gives you all the summary statistic including the mean for your all variables.
summ_result
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句