[R] cumulative sum in data frame
SEUNG CHEON HONG
seunghong at wisc.edu
Wed Jun 17 17:48:56 CEST 2009
Dear R-Help List,
I have a question about data manipulation. I tried to make code myself but too much for me. I would greatly appreciate your help.
I have data set consisting of site (from 1 to N1) and distance and there are several variables (1 to N2) collected from each sampling site. I am interested in looking at cumulative sums of each variable based on site and distance like below.
Can anyone help create function to do the task? The cumulative sum outputs may not be necessarily combined with original data. It will be better to have only cumulative sum outputs and indicator variables of interest.
site distance var1 … var(n2) cu.sum.v1 … cu.sum.v(n2)
1 10 1 0 1 0
1 20 0 1 1 1
1 30 1 2 2 3
1 40 3 3 5 6
1 50 1 4 6 10
2 10 1 1 1 1
2 20 2 1 3 2
2 30 4 1 7 3
2 40 0 1 7 4
2 50 1 1 8 5
,,, ,,, ,,, ,,, ,,,
n1 10 1 1 1 1
n1 20 1 0 2 1
n1 30 1 1 3 2
n1 40 1 0 4 2
n1 50 1 1 5 3
Thank you very much for reading and time!!!
Steve Hong
More information about the R-help
mailing list