0

A while back I conducted multiple imputations with mice() 20 times, and saved these using the following:

for (i in 1:20)
{
  write.csv(complete(imp20, i), file=paste("imp", i, ".csv", sep=""))
}

Now I would like to derive an average n and % for a variable named "remitted" (referring to remission in psychosis) by “sexabuse” (this variable refers to childhood sexual abuse) across all of these 20 data-frames. Rather than doing it 20 times separately and then deriving an average by hand I was hoping there was an easier way of doing it in R. I will be grateful for any suggestions. A small proportion of my data is presented below. Thank you for your help.

> 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
  • Can you merge the data frames? Or make a merged df with only the data you need to calculate the average? – csgroen Aug 21 '17 at 15:20

1 Answers1

0

If I understand you question correctly (you want to find the mean of 20 different data.frame). Then you can do the following:

    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