peerchristensen / cohorts Goto Github PK
View Code? Open in Web Editor NEWAn R package for easy cohort analysis with event data
License: Other
An R package for easy cohort analysis with event data
License: Other
Prepare for release:
git pull
urlchecker::url_check()
devtools::build_readme()
devtools::check(remote = TRUE, manual = TRUE)
devtools::check_win_devel()
revdepcheck::revdep_check(num_workers = 4)
cran-comments.md
git push
Submit to CRAN:
usethis::use_version('minor')
devtools::submit_cran()
Wait for CRAN...
usethis::use_github_release()
usethis::use_dev_version(push = TRUE)
Thank you for creating the cohorts package! I was looking for something to help me analyze donor retention across years and this package and explanation was far and away the simplest thing I found.
However, I wanted to look at years rather than months, so I created a new function with very minor changes that uses lubridate instead of zoo:
cohort_table_year <- function(df, id_var, date)
{
dt <- dtplyr::lazy_dt(df)
dt %>% dplyr::rename(id = {
{
id_var
}
}) %>% dplyr::group_by(id) %>% dplyr::mutate(year = lubridate::year({
{
date
}
})) %>% dplyr::mutate(cohort = min(year)) %>% dplyr::group_by(cohort,
year) %>% dplyr::summarise(users = dplyr::n_distinct(id)) %>%
tidyr::pivot_wider(names_from = year, values_from = users) %>%
dplyr::ungroup() %>% dplyr::mutate(cohort = 1:dplyr::n_distinct(cohort)) %>%
tibble::as_tibble()
}
Feel free to add this (and/or rewrite with zoo instead).
@PeerChristensen many thanks for this package. I used it for one of my analysis. One thing I found out in the source code is that the values being calculated seem to be a count of the rows (n) and not n_distinct(var_id). I believe to get the no of users we need to count the distinct user_ids ?
i.e. instead of
dplyr::summarise(users = dplyr::n()) %>%
we have
dplyr::summarise(users = dplyr::n_distinct({{ id_var }})) %>%
A great job with the package. It makes pulling Twitch data pretty simple.
I do have one request, being able to pull down historical data (i.e not just the current month) would be really useful.
TX
David
Hello Peer,
Thanks for your package. I find it very useful and convenient.
Since I am using a large customer base, the process to get the monthly or the daily cohorts take a little while, so I converted your code to data.table
(and a little bit of tidytable
) and I see already an improvement. Even for the small dataset you include online_cohorts
in the package I see an improvement of 2x.
If you are interested, I can send to you the code to extend your package with them.
Thanks,
Carlos.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.