# [R] manipulating multiply imputed data sets

From: Donald Braman <dbraman_at_law.gwu.edu>
Date: Wed, 28 May 2008 14:20:54 -0400

Hi folks,

I have five imputed data sets and would like to apply the same recoding routines to each. I could do this sort of thing pretty easily in Stata using MIM, but I've decided to go cold turkey on other stats packages as a incentive for learning more about R. Most of the recoding is for nominal variables, like race, religion, urbanicity, and the like. So, for example, to recode race for my first dataset, inmi1, I would do the following:

```miset1\$white  <- recode(miset1\$RACE, '1=1; else=0; ')
miset1\$black  <- recode(miset1\$RACE, '2=1; else=0; ')
miset1\$asian  <- recode(miset1\$RACE, '3=1; else=0; ')
miset1\$hispanic <- recode(miset1\$RACE, '4=1; else=0; ')
miset1\$raceother <- recode(miset1\$RACE, '5=1; else=0; ')

```

I've tried a number of variations, e.g., on the following using recode (from the car package) with imputationList (from the mitools package), though without success:

files.allmisets <- list.files(getwd(),pattern="miset*.csv\$",full=TRUE) allmis <- imputationList(lapply(files.allmisets, read.csv)) allmis <- update(allmis, white <- recode(RACE, '1=1; else=0; '))

I've also tried some basic loops. I guess I'm also a bit confused as to when R references the original object and when it creates a new one. I suppose I could do this in Python and the use PyR, but I'd really like to learn a bit more about how R syntax.

Any help on this specific problem or general advice on manipulating data in multiply imputed datasets in R would be much appreciated.

```--
Donald Braman
http://www.law.gwu.edu/Faculty/profile.aspx?id=10123
http://research.yale.edu/culturalcognition
http://ssrn.com/author=286206

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help