R bloggers

Tidyverse and data.table, sitting side by side… and then base R walks in

FavoriteLoadingAdd to favorites

Of course, I’m paraphrasing Dirk’s fifteenth post in the rarely rational R rambling series: #15: Tidyverse and data.table, sitting side by side … (Part 1). I very much liked it, because, although I’m a happy tidyverse user, I’m always trying not to be tied into that verse too much by replicating certain tasks with other tools (and languages) as an exercise. In this article, I’m going to repeat Dirk’s exercise in base R. First of all, I would like to clean up the tidyverse version a little, because the original was distributed in chunks and was a little bit too verbose. We can also avoid using lubridate, because readr already parses the end_date column as a date (and that’s why it is significantly slower, among other reasons). This is how I would do it: library(tidyverse) library(zoo) polls_2016 <- read_tsv(url(“http://elections.huffingtonpost.com/pollster/api/v2/questions/16-US-Pres-GE%20TrumpvClinton/poll-responses-clean.tsv”)) polls_2016 <- polls_2016 %>% filter(sample_subpopulation %in% c(“Adults”,”Likely Voters”,”Registered Voters”)) %>% right_join(data.frame(end_date…
Original Post: Tidyverse and data.table, sitting side by side… and then base R walks in