【问题标题】:use variabel (which contains the column-index) in dplyr select在 dplyr select 中使用变量(包含列索引)
【发布时间】:2022-06-13 20:21:47
【问题描述】:

当我有一个变量时:

col_to_select = 2

我想在我的dplyr::select 中使用该变量的值,我该怎么做?

mtcars %>% 
  select(col_to_select)

显然给了我这个错误:

Error in `select()`:
! Can't subset columns that don't exist.
x Column `col_to_select` doesn't exist.

我知道这与整洁的评估有关。但是我现在找不到解决方案:/

【问题讨论】:

  • 它在这里工作(不需要 tidyeval),但最好使用all_of(col_to_select)
  • 这里也可以。也许你应该更新你的dplyr

标签: r tidyverse tidyeval


猜你喜欢
  • 2021-09-21
  • 2021-04-23
  • 2017-11-28
  • 2017-09-18
  • 1970-01-01
  • 2016-03-29
  • 2018-01-22
  • 2013-01-29
  • 1970-01-01
相关资源
最近更新 更多