Created
August 31, 2015 17:49
-
-
Save infotroph/d4dfa87e3692c45b43dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dat = data.frame( | |
userID=c("one", "two", "three", "four", "five"), | |
start_date=as.Date(c("2015-09-01", "2015-09-02", "2015-09-02", "2015-09-03", "2015-09-03")), | |
end_date=as.Date(c("2015-09-02", NA, "2015-09-03", NA, "2015-09-03"))) | |
n_start = 100 # number of active users on day zero | |
days = as.Date("2015-08-25")+1:10 | |
n_new = sapply(days, function(x)length(which(dat$start_date == x))) | |
n_lost = sapply(days, function(x)length(which(dat$end_date == x))) | |
dn = n_new - n_lost | |
n_active = cumsum(c(n_start, dn)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment