From: Emilio Gagliardi <emilio_at_ualberta.ca>

Date: Sun, 02 Mar 2008 11:28:13 -0700

}

pattern <- ls(patt='^test\\.[0-9]') # doesn't work variables only exist in the loop

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. Received on Sun 02 Mar 2008 - 18:33:25 GMT

Date: Sun, 02 Mar 2008 11:28:13 -0700

Thank you for your help, but it doesn't produce what I'm looking for...

On Sun, Mar 2, 2008 at 10:50 AM, Henrique Dallazuanna <wwwhsd_at_gmail.com> wrote:

> One options is:

*>
**> data.1 <- matrix(seq(from=1,to=9,by=1),nrow=3,ncol=3)
**> data.2 <- matrix(seq(from=11,to=19,by=1),nrow=3,ncol=3)
**> data.3 <- matrix(seq(from=21,to=29,by=1),nrow=3,ncol=3)
**> data.4 <- matrix(seq(from=31,to=39,by=1),nrow=3,ncol=3)
**> data.5 <- matrix(seq(from=41,to=49,by=1),nrow=3,ncol=3)
**> data.6 <- matrix(seq(from=51,to=59,by=1),nrow=3,ncol=3)
**>
**> patt <- ls(patt='^data\\.[0-9]')
**> nsubs <- 2
**> ngroups <- 3
**> apply(array(as.vector(sapply(patt, get)), dim = c(dim(get(patt[1])),
**> ngroups, nsubs)), 3, mean)
*

generated [1] 20 30 40

but what I need is an average per cell...so in the above, there are 6 (3 x 3) matrices across 3 groups ( 2 subjects per group)..what I need is 1 matrix per group, not one mean. Moreover, I'm storing the data in a single multi-dimensional array, not as a collection of arrays since I'm creating each data matrix within a loop (I read a file, create the data matrix, store it in a larger structure) so that I can perform operations on all the data outside of the loop...

for(i in 1:6)

{

str <- paste("test",i,sep=".") str <- matrix(seq(from=1,to=9,by=1),nrow=3,ncol=3) # works, creates 6matrices

}

pattern <- ls(patt='^test\\.[0-9]') # doesn't work variables only exist in the loop

which is why I had:

subject.data[,,1,1] <- data.1 # subject 1 group 1 subject.data[,,2,1] <- data.2 # subject 1 group 2 subject.data[,,3,1] <- data.3 # subject 1 group 3 subject.data[,,3,2] <- data.4 # subject 2 group 3 subject.data[,,2,2] <- data.5 # subject 2 group 2 subject.data[,,1,2] <- data.6 # subject 2 group 1

to demonstrate all the data was in a meta structure so that I could access them later...am I making this more complicated than it needs to be? How can I create the matrices inside a loop and have them available outside of it?

thanks again,

[[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. Received on Sun 02 Mar 2008 - 18:33:25 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Sun 02 Mar 2008 - 19:30:57 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*