khazaei at ceremade.dauphine.fr
2010-Mar-11 12:44 UTC
[R] divid the rows of the matrix by the cector
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
See ?sweep On Thu, Mar 11, 2010 at 9:44 AM, <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. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
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