[R] Storing loop output in matrix

David Winsemius dwinsemius at comcast.net
Mon Jan 31 23:43:02 CET 2011


On Jan 31, 2011, at 4:49 PM, Dean Castillo wrote:

> Hello
> I am trying to store output from a loop into an empty matrix. The
> current code I am using is:
>> M<-mat.or.vec(11,89)

R code to create a matix would use the matrix function,
>> for (j in list(3,91))
> + {M[,(j-2)]<-pic(datain[,j], mytree)}
>

You seem to be coming from a programming paradigm tha t uses "," where  
R would use ":"

list(3,91) is a two element object rather than 3:91 which would be an  
89 element object.

Perhaps you should read some introductory material and get a better  
handle in the R syntax through self study.

http://cran.r-project.org/doc/manuals/R-intro.pdf



> datain is a matrix (11,91). I only want to use the pic() function on
> the columns 3:91.

What pic function???
 > ?pic
No documentation for 'pic' in specified packages and libraries:
you could try '??pic'


> When I use this code output is stored into the 1st column of M and the
> 89th column of M but no other columns.
>
> Any help would be greatly appreciated
>
> Dean

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list