Skip to content

Instantly share code, notes, and snippets.

@erykml
Created July 25, 2019 00:39
Show Gist options
  • Select an option

  • Save erykml/f6a1e9f0e7d498f426f4df6477af8d31 to your computer and use it in GitHub Desktop.

Select an option

Save erykml/f6a1e9f0e7d498f426f4df6477af8d31 to your computer and use it in GitHub Desktop.
data_dt_lazy <- lazy_dt(data_dt, immutable=FALSE)
mbm <- microbenchmark("dplyr" = {
result_df <- data_df %>%
filter(amount <= 4000) %>%
mutate(order_value = amount * price) %>%
group_by(id) %>%
summarise(avg_order_value = mean(order_value))
},
"data.table" = {
result_dt <- data_dt[amount <= 4000][, order_value := amount * price][, .(avg_order_value = mean(order_value)), keyby = id]
},
"dtplyr" = {
result_dtplyr <- data_dt_lazy %>%
filter(amount <= 4000) %>%
mutate(order_value = amount * price) %>%
group_by(id) %>%
summarise(avg_order_value = mean(order_value)) %>%
as.data.table()
})
mbm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment