[R] data frame and cumulative sum

Giovanni Azua bravegag at gmail.com
Wed Dec 7 23:13:30 CET 2011


Hello,

I have a data frame that looks like this (containing interarrival times):

> str(df)
'data.frame':	18233 obs. of  1 variable:
 $ Interarrival: int  135 806 117 4 14 1 9 104 169 0 ...
> head(df)
  Interarrival
1          135
2          806
3          117
4            4
5           14
6            1
> 

This corresponds to the time differences (in ms) of a poisson arrival process where Interarrival{i+1} = time_{i+1} - time_{i}

I want to get the Time bin (in minutes) of every interarrival basically something like:

1) df$Time <- sum(of all df$Interarrival up to "this rownum") # cumulative sum
 
2) df$Time <- floor(df$Time / 60000) + 1

then I should get the first minute of Interarrival having 1 and so forth. The problem is I have no idea how to accomplish 1) in R.

Can anyone advice? 

Thanks in advance,
Best regards,
Giovanni


More information about the R-help mailing list