[R] Averaging over data sets

Felipe Nunes
Fri, 13 Jan 2012 06:16:03 -0000

Hi all,

after using Amelia II to create 10 imputed data sets I need to average them
to have one unique data that includes the average for each cell of the
variables imputed, in addition to the values for the variables not imputed.
Such data has many variables (some numeric, other factors), and more than
20000 observations. I do not know how to average them out. Any help?

Below I provide a small example:

Suppose Amelia provided two datasets:

d1 <- data.frame(subject = c("Felipe", "John"), eat1 =
1:2, eat3 = 5:6, trt
= c("t1", "t2"))

d2 <- data.frame(subject = c("Felipe", "John"), eat1 =
3:4, eat3 = 6:7, trt
= c("t1", "t2"))

I tried

(d1 + d2)/2

but I lose my factors. mean() did not work either.

The result I'd like is:

     subject  eat1  eat3   trt
1   Felipe     2      5.5     t1
2     John      3      6.5     t2

thanks,

*Felipe Nunes*
CAPES/Fulbright Fellow
PhD Student Political Science - UCLA
Web: felipenunes.bol.ucla.edu

	[[alternative HTML version deleted]]