[R] Loop

Berend Hasselman bhh at xs4all.nl
Wed Feb 22 14:46:50 CET 2012

On 22-02-2012, at 14:40, Florian Weiler wrote:

> Thanks for the answer, and sorry if I was not clear.
> So I run the data imputation using mice with 10 chains and then I get a
> mids-object. From that object I can then extract 10 data sets using the
> complete(imp, n) command (with n=c(1:10)).
> Now I can type this out 10 times:
> set1 <- complete(imp, 1) 
> set2 <- complete(imp, 2)
> etc.
> Each of these set1 to set10 will be a data frame. That all is easy enough,
> but I would like to do this in a loop and create the same 10 data sets. 
> If I use the command proposed by you, then the loop works but again the 10
> data sets are stored in only one single object (a list) when I would like to
> create 10 separate data sets. 
> Is that enough information?

How about this

for( k in 1:10 )  assign(paste("set",k,sep=""), complete(imp,k))

Berend Hasselman

More information about the R-help mailing list