How to get the final query in data.table format?
if not possible: how to rewrite the query from dplyr to data.table ?
library(data.table)
library(dplyr)
library(dtplyr)
#Data
dt = structure(list(Year = c(2015L, 2016L, 2017L, 2015L, 2016L, 2017L),
Item = c("Soybeans", "Soybeans", "Soybeans", "Pulses, Total", "Pulses, Total", "Pulses, Total"),
Value = c(884688L, 829166L, 960640L, 2219455L, 2354696L, 2683772L)),
row.names = c(NA, -6L), class = "data.frame")
# query in dplyr
dt %>%
group_by(Year) %>%
summarise(Value = sum(Value), Item = "Total") %>%
bind_rows(., dt)
#conveert query to data.table
dtl=lazy_dt(dt)
dtl %>%
group_by(Year) %>%
summarise(Value = sum(Value), Item = "Total") %>%
bind_rows(., dtl) %>% show_query()
Error: Argument 1 must be a data frame or a named atomic vector.