简体   繁体   中英

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)]

You'd use get :

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM