Fabio Sanchez
2006-Oct-19 11:49 UTC
[R] Writing a script for multiplying a progressively larger lists of items
Hi, I would like to get guidance as to how to write code in R that can deal with the following situation: v1 is a vector containing a sequence of numbers (Ex. 1:10) I want to store the sequence of numbers resulting from multiplying the first and the second element in the vector, then the product of the 1st, 2nd and 3rd, then 1st,2nd,3rd and 4th and so forth until all the elements in the vector are multiplied. Many thanks, Fabio Fabio S?nchez, MD, MSc, PhD Molecular Dermatology Department of Medicine Karolinska Institute SE-17176 Karolinska University Hospital Tel: +46 8 51772158
Dimitris Rizopoulos
2006-Oct-19 12:02 UTC
[R] Writing a script for multiplying a progressively larger listsof items
probably you're looking for ?cumprod(), e.g., cumprod(1:10) 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: "Fabio Sanchez" <Fabio.Sanchez at ki.se> To: <r-help at stat.math.ethz.ch> Sent: Thursday, October 19, 2006 1:49 PM Subject: [R] Writing a script for multiplying a progressively larger listsof items Hi, I would like to get guidance as to how to write code in R that can deal with the following situation: v1 is a vector containing a sequence of numbers (Ex. 1:10) I want to store the sequence of numbers resulting from multiplying the first and the second element in the vector, then the product of the 1st, 2nd and 3rd, then 1st,2nd,3rd and 4th and so forth until all the elements in the vector are multiplied. Many thanks, Fabio Fabio S?nchez, MD, MSc, PhD Molecular Dermatology Department of Medicine Karolinska Institute SE-17176 Karolinska University Hospital Tel: +46 8 51772158 ______________________________________________ R-help at stat.math.ethz.ch 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