product of vector elements

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

product of vector elements

Gerard Smits
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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: product of vector elements

Chuck Cleland
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]]
>
> ______________________________________________
> [hidden email] 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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: product of vector elements

Gabor Grothendieck
In reply to this post by Gerard Smits
help.search("product")

On Jan 12, 2008 7:38 PM, Gerard Smits <[hidden email]> 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]]
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: product of vector elements

Daniel Nordlund
In reply to this post by Gerard Smits
> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On Behalf
> Of Gerard Smits
> Sent: Saturday, January 12, 2008 4:39 PM
> To: [hidden email]
> 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,
>
> Gerard

See ?prod.

Hope this is helpful,

Dan

Daniel Nordlund
Bothell, WA  USA

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: product of vector elements

Gerard Smits
In reply to this post by Gabor Grothendieck
Thanks for cumprod() and prod().

I should have tried the help.search first.  Next time ....

Gerard

At 04:55 PM 1/12/2008, Gabor Grothendieck wrote:

>help.search("product")
>
>On Jan 12, 2008 7:38 PM, Gerard Smits <[hidden email]> 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]]
> >
> > ______________________________________________
> > [hidden email] 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.
> >

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.