[R] using mean substitution

Michael Parent michael.parent at ufl.edu
Mon Oct 17 23:35:18 CEST 2011


Hi, all,

I'm running a monte carlo simulation with missing data. The data are arranged such that there are k columns and n rows over a set number of simulations (set to 10 right now so it runs fast while I set everything up). The data are integers, numbers 1-7 only (normal distribution). The simulations are set up and run without a hitch, including imposing NA missing values at a specified prevalence semi-randomly (there are not allowed to be any completely empty rows).

I'd like to replace the missing values ("NA") with the mean for the non-missing items items *on that row*.  I want to go through all the monte carlo simulation runs that I already did (so that I'm using the same data) and replace NA with the mean (e.g., if k=5 and a row has values of 3 3 NA 5 5, I want to put a 4 in for NA). I also want the imputed mean values to be rounded to the nearest integer.

Does anyone have an idea for how I'd set that up? I feel like there's a fairly easy way to set up searching out those NAs and replacing the the row mean that is not coming to me.

Thanks,
Mike


More information about the R-help mailing list