[R] Summing a series made up of part of a vector
David Winsemius
dwinsemius at comcast.net
Wed Apr 7 14:40:05 CEST 2010
On Apr 7, 2010, at 8:26 AM, Simon Kiss wrote:
> 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.
>
?cumsum
> x5
> 1 4.2
> 2 7.8 (4.2 +3.6)
> 3 10.5 (4.2+3.6+2.7)
>
> 308 =na
Now that might pose problems. How do you define sum( c(1, 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
>
> ______________________________________________
> 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.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list