Dear All, Is there a conmand to calculate the multiplication of the elements in a vector? For example: a=c(1,2,3,4) I want to get 1*2*3*4=24. Because the dimension of the vector is high, I want to know there is a command for this task in R? Thank you so much! Kang __________________________________________________ [[alternative HTML version deleted]]
look at ?prod(), e.g.,
prod(a)
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Guolian Kang" <statphyskang at yahoo.com>
To: <r-help at stat.math.ethz.ch>
Sent: Wednesday, October 24, 2007 5:37 AM
Subject: [R] multiply for vector in R
> Dear All,
>
> Is there a conmand to calculate the multiplication of the elements
> in a vector? For example:
>
> a=c(1,2,3,4)
> I want to get 1*2*3*4=24.
> Because the dimension of the vector is high, I want to know there is
> a command for this task in R?
>
> Thank you so much!
>
> Kang
>
> __________________________________________________
>
>
>
> [[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.
>
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
?prod On 24 Oct 2007, at 05:37, Guolian Kang wrote:> Dear All, > > Is there a conmand to calculate the multiplication of the elements > in a vector? For example: > > a=c(1,2,3,4) > I want to get 1*2*3*4=24. > Because the dimension of the vector is high, I want to know there > is a command for this task in R? > > Thank you so much! > > Kang > > __________________________________________________ > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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.Ingmar Visser Department of Psychology, University of Amsterdam Roetersstraat 15 1018 WB Amsterdam The Netherlands t: +31-20-5256723 [[alternative HTML version deleted]]
Guolian Kang wrote on 10/24/2007 01:37 PM:> Dear All, > > Is there a conmand to calculate the multiplication of the elements in a vector? For example: > > a=c(1,2,3,4) > I want to get 1*2*3*4=24. > Because the dimension of the vector is high, I want to know there is a command for this task in R? > > Thank you so much! > > Kang > >?prod Ted. -- Dr E.A. Catchpole Visiting Fellow Univ of New South Wales at ADFA, Canberra, Australia _ and University of Kent, Canterbury, England 'v' - www.pems.adfa.edu.au/~ecatchpole / \ - fax: +61 2 6268 8786 m m - ph: +61 2 6268 8895