相关疑难解决方法(0)

在 dplyr 中使用带有部分列名向量的 starts_with

我想使用 dplyr 来选择与字符串向量匹配的某些列。

one <- seq(1:10)
two <- rnorm(10)
three <- runif(10, 1, 2)
four <- -10:-1

df <- data.frame(one, two, three, four)

vars <- c('on', 'thr')
Run Code Online (Sandbox Code Playgroud)

我只想选择 df 中标题以“on”或“thr”开头的列:

dplyr::select_(df, starts_with(vars))
Run Code Online (Sandbox Code Playgroud)

但是,上述方法不起作用。

r dplyr

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

dplyr ×1

r ×1