【发布时间】:2018-08-24 19:19:41
【问题描述】:
我知道有很多关于此的帖子,但我找不到任何有帮助的帖子。我想做的很简单。
我想根据列名中是否存在字母来选择(或删除)列。
library(tibble)
library(stringr)
library(dplyr)
xy <- tibble("x" = 1:5, "123" = 6:10, "x123" = 11:15)
#does not have expected output
> xy %>% select(-matches("[:alpha:]"))
# A tibble: 5 x 3
x `123` x123
<int> <int> <int>
1 1 6 11
2 2 7 12
3 3 8 13
4 4 9 14
5 5 10 15
但如果我使用str_view_all,所有结果都符合预期,但不适用于dplyr 辅助函数matches 用于选择列。
str_view_all(x, "[:alpha:]")
如果可能,我正在寻找使用stringr 和dplyr 的解决方案。看起来这应该很简单。
【问题讨论】: