Re: [R] operations on all pairs of columns from two matrices

From: Stephen Tucker <brown_emu_at_yahoo.com>
Date: Wed, 18 Jun 2008 08:01:56 -0700 (PDT)


how about this?

m1 <- matrix(rep(1:3,each=5),ncol=3)
m2 <- matrix(1:15,ncol=3)

array(apply(m1,2,function(x,m) m-x,m2),dim=c(dim(m2),ncol(m1)))

m1 <- matrix(rnorm(40), ncol=4)
m2 <- matrix(rnorm(40), ncol=4)

I would like to subtract first column of m1 from all columns of m2, subtract 2nd of m1 from all columns of m2, and so on. Obviously, I am not using the appropriate function outer(m1, m1, "-"), since the first column isn't all 0s.


    [[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.

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 Wed 18 Jun 2008 - 18:17:37 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 Wed 18 Jun 2008 - 18:30:50 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.

list of date sections of archive