[R] Simplifying my code
R. Michael Weylandt <michael.weylandt@gmail.com>
michael.weylandt at gmail.com
Sun Nov 27 18:52:04 CET 2011
But it's much better to preallocate memory:
dat = vector("list", 20)
or
dat = vector("numeric", 20)
or
dat = matrix(nrow = 20, ncol = ??)
as needed (put the right # of columns in for the matrix)
Michael
On Nov 27, 2011, at 11:24 AM, andrija djurovic <djandrija at gmail.com> wrote:
> Hi.
> You haven't specified object to store results.
>
> Try something like:
>
> dat = c() #or dat = list() or matrix with specified ncol and nrow
> for(i in 1:20){
>
> dat[i]=complete(dat.mice,[i]
>
> }
>
> On Sun, Nov 27, 2011 at 4:02 PM, Christopher Desjardins <desja004 at umn.edu>wrote:
>
>> Hi,
>> I have a pretty simple problem. Here is the code:
>>
>> dat1=complete(dat.mice,1)
>>
>> dat2=complete(dat.mice,2)
>>
>> dat3=complete(dat.mice,3)
>>
>> dat4=complete(dat.mice,4)
>>
>> dat5=complete(dat.mice,5)
>>
>> dat6=complete(dat.mice,6)
>>
>> dat7=complete(dat.mice,7)
>>
>> dat8=complete(dat.mice,8)
>>
>> dat9=complete(dat.mice,9)
>>
>> dat10=complete(dat.mice,10)
>>
>> dat11=complete(dat.mice,11)
>>
>> dat12=complete(dat.mice,12)
>>
>> dat13=complete(dat.mice,13)
>>
>> dat14=complete(dat.mice,14)
>>
>> dat15=complete(dat.mice,15)
>>
>> dat16=complete(dat.mice,16)
>>
>> dat17=complete(dat.mice,17)
>>
>> dat18=complete(dat.mice,18)
>>
>> dat19=complete(dat.mice,19)
>>
>> dat20=complete(dat.mice,20)
>>
>>
>> I would like to simplify this into a for loop. I thought this would work:
>>
>> for(i in 1:20){
>>
>> dat[i]=complete(dat.mice,[i]
>>
>> }
>>
>> But it doesn't. Any tips?
>>
>> Chris
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list