Skip to content

Loop

5 messages · Helios de Rosario, Florian Weiler, Berend Hasselman +1 more

#
-- 
Helios de Rosario Mart?nez
 
 Researcher
escribi?:
mice
the
follows:
must
Hi Florian,

Please give more context. There are various reasons why that could
fail. Is your list "set" defined before starting to assign values?

Try:
set <- vector("list",10)
before the loop.



INSTITUTO DE BIOMEC?NICA DE VALENCIA
Universidad Polit?cnica de Valencia ? Edificio 9C
Camino de Vera s/n ? 46022 VALENCIA (ESPA?A)
Tel. +34 96 387 91 60 ? Fax +34 96 387 91 69
www.ibv.org

  Antes de imprimir este e-mail piense bien si es necesario hacerlo.
En cumplimiento de la Ley Org?nica 15/1999 reguladora de la Protecci?n
de Datos de Car?cter Personal, le informamos de que el presente mensaje
contiene informaci?n confidencial, siendo para uso exclusivo del
destinatario arriba indicado. En caso de no ser usted el destinatario
del mismo le informamos que su recepci?n no le autoriza a su divulgaci?n
o reproducci?n por cualquier medio, debiendo destruirlo de inmediato,
rog?ndole lo notifique al remitente.
#
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?

Thanks again,
Florian

--
View this message in context: http://r.789695.n4.nabble.com/Loop-tp4409865p4410333.html
Sent from the R help mailing list archive at Nabble.com.
#
On 22-02-2012, at 14:40, Florian Weiler wrote:

            
How about this

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


Berend Hasselman
#
Le mercredi 22 f?vrier 2012 ? 05:40 -0800, Florian Weiler a ?crit :
With the suggested solution, you get a list of data sets. You can access
each data set separately as if it was a separate object, e.g. using
set[[1]]. It's usually more practical to have all objects in a list,
this allows you to run actions on all of them easily using lapply() and
things like that.

Hope this helps