[R] data frame and cumulative sum
Giovanni Azua
bravegag at gmail.com
Wed Dec 7 23:53:44 CET 2011
Thank you Michael,
indeed, my bad, I get so deep in trying to solve the problem that forget to try the most basic help first.
Best regards,
Giovanni
On Dec 7, 2011, at 11:20 PM, R. Michael Weylandt wrote:
> ??"cumulative sum" would almost certainly lead you to cumsum with only
> a modicum of effort
>
> Michael
>
> On Wed, Dec 7, 2011 at 5:13 PM, Giovanni Azua <bravegag at gmail.com> wrote:
>> 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
>> ______________________________________________
>> 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.
More information about the R-help
mailing list