Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(magrittr)
- library(plyr)
- library(dplyr)
- set.seed(100)
- numCate <- 5000
- N <- 1e6
- cates <- sample(paste0("A", 1:numCate), N, TRUE)
- time <- sample(1:300, N, TRUE)
- dat <- data.frame(cates, time, stringsAsFactors = FALSE) %>% tbl_df
- st <- proc.time()
- dat_out <- ddply(dat, .(cates), function(sub_df){
- sub_df %>% arrange(time) %>% filter(diff(c(0, time)) > 1)
- }) %>% tbl_df
- proc.time() - st
- # user system elapsed
- # 6.13 0.00 6.21
- library(foreach)
- library(doSNOW)
- cl <- makeCluster(8, type = "SOCK")
- registerDoSNOW(cl)
- st <- proc.time()
- dat_out <- ddply(dat, .(cates), function(sub_df){
- sub_df %>% arrange(time) %>% filter(diff(c(0, time)) > 1)
- }, .parallel=TRUE) %>% tbl_df
- proc.time() - st
- # user system elapsed
- # 2.85 0.58 4.32
- stopCluster(cl)
Advertisement
Add Comment
Please, Sign In to add comment