aggregate - Sum up values according to time R -


i need sum values according timeline, here's data

           userid user_count       time 215981 1702099122          1 2014-10-16 762721 2631243080          1 2014-11-17 806291 2753297247          1 2014-10-13 927621 3177288950          1 2014-11-22 136961 1632673193          1 2015-10-12 374601 1801088453          1  2015-11-9 

if use aggregate add column called user_time

user_time <- aggregate(user_count ~time, df, sum) 

then total user_count on each day, user_time 1. however, want compute sum each day. example, user_time on 2014-11-22 should 4, on 2014-10-16 should 2. wonder how properly. thank you.

perhaps need cumsum

library(dplyr) df %>%       arrange(time) %>%      mutate(count = cumsum(user_count)) 

or using base r

 transform(df[order(df$time),], count = cumsum(user_count)) 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -