All, I would like to find a simper method that I now have to find the product of all elements in a vector: #get product of vector elements: (1,2,3,4,5) vec.product <- exp(sum(log(c(1,2,3,4,5)))) I have not found a vector product function, if one has been written. Thanks, Gerard [[alternative HTML version deleted]]
On 1/12/2008 7:38 PM, Gerard Smits wrote:> All, > > I would like to find a simper method that I now have to find the > product of all elements in a vector: > > #get product of vector elements: (1,2,3,4,5) > vec.product <- exp(sum(log(c(1,2,3,4,5)))) > > I have not found a vector product function, if one has been written.> cumprod(1:5) [1] 1 2 6 24 120 ?cumprod> Thanks, > > Gerard > [[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.-- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894
help.search("product") On Jan 12, 2008 7:38 PM, Gerard Smits <g_smits at verizon.net> wrote:> All, > > I would like to find a simper method that I now have to find the > product of all elements in a vector: > > #get product of vector elements: (1,2,3,4,5) > vec.product <- exp(sum(log(c(1,2,3,4,5)))) > > I have not found a vector product function, if one has been written. > > Thanks, > > Gerard > [[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. >
> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf > Of Gerard Smits > Sent: Saturday, January 12, 2008 4:39 PM > To: r-help at r-project.org > Subject: [R] product of vector elements > > All, > > I would like to find a simper method that I now have to find the > product of all elements in a vector: > > #get product of vector elements: (1,2,3,4,5) > vec.product <- exp(sum(log(c(1,2,3,4,5)))) > > I have not found a vector product function, if one has been written. > > Thanks, > > GerardSee ?prod. Hope this is helpful, Dan Daniel Nordlund Bothell, WA USA