Re: [R] Multiplying each row of a big matrix with a vector

From: <Bill.Venables_at_csiro.au>
Date: Wed, 30 Jan 2008 17:52:56 +1000

port <- as.vector(ret %*% port)

should do it.

Bill Venables

-----Original Message-----
From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org] On Behalf Of Megh Dal
Sent: Wednesday, 30 January 2008 5:20 PM To: r-help_at_stat.math.ethz.ch
Subject: [R] Multiplying each row of a big matrix with a vector

I have a big matrix 'ret'. I want to multiply each row of it with a 2nd vector 'pos', resulting result, I want to save in a vector named 'port'. I wrote following code:    

> pos

[1] 2593419 2130220 6198197 1673888 1980000 1784732 2052120 -7490228 -5275000    

> dim(ret)

[1] 500 9

> fu # user defined function
function(x)

   {
    fu = x %*% t(pos)
   }
port = apply(ret, 1, fu)

> dim(port)

[1] 81 500

  My desire is to get port as a vector with length 500. However I am not getting that?    

  Can anyone tell me how to correct that?    

  Regards,            


        [[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 30 Jan 2008 - 07:56:32 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 30 Jan 2008 - 08:30:09 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