[R] creating an index vector within a 'for' loop

Adaikalavan Ramasamy ramasamy at stats.ox.ac.uk
Mon Jul 29 11:49:25 CEST 2002


I am assuming your outputs are not scalar. You might want to use list()
function. Try :

xy.list <- list(NULL)   # initialise an list with null attributes

 for (i in 1:10) {
   xy.list[[i]] <- X%*%Y   }

Note the double square bracket. So xy.list[[8]] should extract the X%*%Y
values for the 8th person.
Hope this helps.

----- Original Message -----
From: <laura at bayesian-bay.freeserve.co.uk>
To: <r-help at stat.math.ethz.ch>
Sent: Monday, July 29, 2002 10:04 AM
Subject: [R] creating an index vector within a 'for' loop


> Dear list
>
> I have what is probably a very simple question that I can't seem to solve.
I basically want to create a vector at the end of a 'for' loop that will
store the output for each person and which I can recall after the loop has
run. This will require some sort of indexing.
>
> X and Y are matrices defined earlier for each person (within the for loop
but I'm not writing it here to cut irrelevant information)
>
> for (i in 1:10) {
> XY[i]<-X%*%Y
> }
>
> Could someone tell me how I can create the matrix that will contain the
output for each of the 10 people?
>
> Many thanks in advance
> Laura
>
>
> _______________________________________________________________________
>
>
>
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-.-
> r-help mailing list -- Read
http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
>
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._
>

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list