[R] Cumulative sum of vector
    Keith Jones 
    keithlj at suddenlink.net
       
    Sat Jan  5 15:32:41 CET 2008
    
    
  
Hi,
Maybe I have not been looking in the right spot, but, I have not been 
able to fine a command to automatically calculate the running 
cumulative sum of a vector.  Is there such a command?
Example of current code:
>  eig$values
[1] 678.365651   6.769697   2.853783
>  prop<-eig$values/sum(eig$values)
>  prop
[1] 0.986012163 0.009839832 0.004148005
>  cum<-c(prop[1],sum(prop[1:2]),sum(prop[1:3]))
>  cum
[1] 0.9860122 0.9958520 1.0000000
This works, but, if the length of the vector changes I have to 
manually change the code.
Thanks,
Keith Jones
    
    
More information about the R-help
mailing list