jyjek
jyjek

Reputation: 2717

summarize column with data.table using rlang

I'm new in data.table
How to make the same thing with data.table using rlang?

library(tidyverse)
library(data.table)

gr <- "Species"
col <- "Petal.Length"

iris %>% 
  group_by(!!rlang::sym(gr)) %>% 
  summarise_at(vars(!!rlang::sym(col)),sum)

iris1 <- iris 
setDT(iris1)
iris1[,sum(!!rlang::sym(col)),by=!!rlang::sym(gr)]

Upvotes: 0

Views: 215

Answers (1)

arg0naut91
arg0naut91

Reputation: 14774

You'd use get:

iris1[, sum(get(col)), by = get(gr)]

As @mmn pointed out, you can also skip get in the by argument.

Upvotes: 5

Related Questions