[R] Summing a series made up of part of a vector

Simon Kiss sjkiss at gmail.com
Wed Apr 7 14:26:12 CEST 2010


Dear colleagues,
I have a data frame that looks so:
*x1 .... x4
1   4.2
2   3.6
3   2.7
.
.
308 n.a.

x4 is a vector of percentages, sorted in descending value. I would  
like to create a new variable that represents the sum of the series of  
values of x4 to that row.  So I would like x5 to look like this.

x5
1 4.2
2 7.8 (4.2 +3.6)
3 10.5 (4.2+3.6+2.7)

308 =na

So the last number in the vector x5 should be 100, as these are all  
percentages.

Any suggestions? Yours truly,
simon Kiss
*********************************
Simon J. Kiss, PhD
SSHRC and DAAD Post-Doctoral Fellow
John F. Kennedy Institute of North America Studies
Free University of Berlin
Lansstraße 7-9
14195 Berlin, Germany
Cell: +49 (0)1525-300-2812,
Web: http://www.jfki.fu-berlin.de/index.html



More information about the R-help mailing list