Re: [R] Working with a set of matrices

From: Wolfgang Huber <huber_at_ebi.ac.uk>
Date: Sun 21 Jan 2007 - 09:57:16 GMT

Dear M(?),

you could pack your matrices into a list or an environment and then iterate through that, either using "for" and subset operator "[[" or using the lapply / eapply functions.

And instead of looping it is sometimes more elegant to put what you want to do with each of your matrices into a function and then repeatedly call the function.

Also have a look at "get" for accessing objects e.g. in the global workspace by their name.

  Best wishes
    Wolfgang



Wolfgang Huber EBI/EMBL Cambridge UK http://www.ebi.ac.uk/huber

M Jones wrote:
> Hi,
>
> I have a set of matrices (MAT.1, MAT.2, ...) and I'd like to perform the same operation on each of them (for simplicity, say . I'm writing a function for this so that it can be repeated for different sets with different numbers of matrices. The matrices have the same number of columns, but do not have the same number of rows.
>
> My thought is to loop thru the set. but I'm not sure how to set the loop up so that the matrix number changes for each cycle. I have tried paste, but that leaves quotation marks around the matrix name (e.g., "MAT.1", and I need just MAT.1), or at least the way I'm using paste..
>
> Any thoughts? If there is a better way than the loop, then I'm of course open to that.
>
> Thanks in advance.
>



R-help@stat.math.ethz.ch 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 Jan 21 21:02:56 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 21 Jan 2007 - 10:30:22 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.