Using variables for column functions in mutate()

前端 未结 2 514
囚心锁ツ
囚心锁ツ 2021-01-19 17:54

How can I use variables in place of column names in dplyr strings? As an example say I want to add a column to the iris dataset called sum that is the sum o

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-19 18:20

    I think that recommended way is using sym:

    iris %>% mutate(sum = !!sym(x) + !!sym(y)) %>% head
    

提交回复
热议问题