[R] divid the rows of the matrix by the cector

(Ted Harding) Ted.Harding at manchester.ac.uk
Thu Mar 11 16:22:03 CET 2010


  matrix(1:12,nrow=3)
  #      [,1] [,2] [,3] [,4]
  # [1,]    1    4    7   10
  # [2,]    2    5    8   11
  # [3,]    3    6    9   12

  t(t(matrix(1:12,nrow=3))/c(2,3,4,5))
  #      [,1]     [,2] [,3] [,4]
  # [1,]  0.5 1.333333 1.75  2.0
  # [2,]  1.0 1.666667 2.00  2.2
  # [3,]  1.5 2.000000 2.25  2.4

Ted.

On 11-Mar-10 12:47:53, Dimitris Rizopoulos wrote:
> say 'mat' is your matrix and 'vec' is your vector, then try this:
> 
> mat / rep(vec, each = m)
> 
> 
> I hope it helps.
> 
> Best,
> Dimitris
> 
> 
> On 3/11/2010 1:44 PM, khazaei at ceremade.dauphine.fr wrote:
>> Hi,
>> I have a matrix with  m rows and n column  and a vector with n
>> elements. I
>> want to divid each rows of the matrix by vector direcly.
>> could you please hint  me?
>>
>> Thank you
>> khazaei
>>
>> ______________________________________________
>> 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.
>>
> 
> -- 
> Dimitris Rizopoulos
> Assistant Professor
> Department of Biostatistics
> Erasmus University Medical Center
> 
> Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
> Tel: +31/(0)10/7043478
> Fax: +31/(0)10/7043014
> 
> ______________________________________________
> 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.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 11-Mar-10                                       Time: 15:22:01
------------------------------ XFMail ------------------------------



More information about the R-help mailing list