Hello again,

Let say I have 2 matrices which equal number of columns but different
number of rows like:

Mat1 <- matrix(1:20, 4, 5)
Mat2 <- matrix(1:25, 5, 5)

Now for each column 1-to-5 I need to fetch the corresponding columns
of these 2 matrices and add the corresponding elements (ignoring NA
values if any). Therefore for the 1st column I need to do:

(1+1), (2+2),...,(4+4), (NA+5)

and so on

And the resulting numbers will be stored in some other matrix

Also note that, here I gave the example of addition, however, this can
be any user defined function.

Is there any R way to do that, without using any for-loop?

Thanks and regards,

______________________________________________
R-help@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.

Reply via email to