dplyr:在NSE中按位置选择列 [英] dplyr: select columns by position in NSE
本文介绍了dplyr:在NSE中按位置选择列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建一个函数,该函数将根据其位置选择DF中的列.我将始终需要第一列,然后是DF的子集.对于每个需要选择的子集,我都有1个对象.
I am trying to create a function that will select columns in a DF based on their position. I will always need the first column and then a subset of the DF. I have 1 object for each subset I need to select.
到目前为止,我已经尝试了以下方法:
So far I have tried the following:
position <- "1,28:31"
DF %>%
select_(.dots = position)
但是我收到以下错误:
解析错误(text = x)::1:2:意外的'x'
Error in parse(text = x) : :1:2: unexpected 'x'
问题似乎在于列位置的逗号分隔.
It would seem the problem is the comma separation in the column position.
有解决方法吗?
推荐答案
您可以将select
与索引的数值向量一起使用:
You can just use select
with a numeric vector of indexes:
positions <- c(1,28:31)
DF %>% select(positions)
这篇关于dplyr:在NSE中按位置选择列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文