[R] On matrix calculation
    Berend Hasselman 
    bhh at xs4all.nl
       
    Wed Apr 17 15:07:11 CEST 2013
    
    
  
On 17-04-2013, at 14:39, Christofer Bogaso <bogaso.christofer at gmail.com> wrote:
> Hello again,
> 
> Let say I have a matrix:
> 
> Mat <- matrix(1:12, 4, 3)
> 
> And a vector:
> 
> Vec <- 5:8
> 
> Now I want to do following:
> 
> Each element of row-i in 'Mat' will be divided by i-th element of Vec
> 
> Is there any direct way to doing that?
What have you tried?
Because of recycling and storage by columns of matrices and  and the fact length(Vec) == nrow(Mat)
Mat / Vec
will do.
Berend
    
    
More information about the R-help
mailing list