Re: [R] matrix column division by vector

2014-05-14 Thread Jeff Newmiller
Scores well on notational simplicity. Loses big on computational efficiency (lots of terms multiplied with zero, then added to the one nonzero term). --- Jeff NewmillerThe . . Go Liv

Re: [R] matrix column division by vector

2014-05-14 Thread Ted Harding
Maybe I am missing the point -- but what is wrong with line 3 of: m=rbind(c(6,4,2),c(3,2,1)) v= c(3,2,1) m%*%diag(1/v) # [,1] [,2] [,3] # [1,]222 # [2,]111 Ted. On 14-May-2014 15:03:36 Frede Aakmann Tøgersen wrote: > Have a look at ?sweep > > Br. Frede >

Re: [R] matrix column division by vector

2014-05-14 Thread Bert Gunter
psed >>5.040.015.06 >> >> David C >> >> -Original Message- >> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On >> Behalf Of Jeff Newmiller >> Sent: Wednesday, May 14, 2014 10:28 AM >> To: carol white; carol white; r-

Re: [R] matrix column division by vector

2014-05-14 Thread Bert Gunter
user system elapsed >5.040.015.06 > > David C > > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of Jeff Newmiller > Sent: Wednesday, May 14, 2014 10:28 AM > To: carol white; carol white;

Re: [R] matrix column division by vector

2014-05-14 Thread David L Carlson
--Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jeff Newmiller Sent: Wednesday, May 14, 2014 10:28 AM To: carol white; carol white; r-h...@stat.math.ethz.ch Subject: Re: [R] matrix column division by vector Please post in plain t

Re: [R] matrix column division by vector

2014-05-14 Thread Jeff Newmiller
Please post in plain text... your email is getting distorted and hard to read by the HTML. I don't know how to use do.call for this, but when you understand how vectors recycle and matrices and arrays are laid out in memory (read the Introduction to R document if not) then the following comes t

Re: [R] matrix column division by vector

2014-05-14 Thread Bert Gunter
Oh my goodness David! Don't forget that matrices are just vectors in column major order. > m/rep(v,e=2) [,1] [,2] [,3] [1,]222 [2,]111 (the generalization is obvious) should be far more efficient and simpler than running apply loops. -- Cheers, Bert Bert Gunter G

Re: [R] matrix column division by vector

2014-05-14 Thread Frede Aakmann Tøgersen
Have a look at ?sweep Br. Frede Sendt fra Samsung mobil Oprindelig meddelelse Fra: carol white Dato:14/05/2014 16.53 (GMT+01:00) Til: r-h...@stat.math.ethz.ch Emne: [R] matrix column division by vector Hi, What is the elegant script to divide the columns of a matrix by the res

Re: [R] matrix column division by vector

2014-05-14 Thread David L Carlson
You don't need do.call: > t(t(m)/v) [,1] [,2] [,3] [1,]222 [2,]111 > t(apply(m, 1, function(x) x/v)) [,1] [,2] [,3] [1,]222 [2,]111 - David L Carlson Department of Anthropology Texas A&M University Coll