[R] Working with a set of matrices
Wolfgang Huber
huber at ebi.ac.uk
Sun Jan 21 10:57:16 CET 2007
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.
>
More information about the R-help
mailing list