1
与向量作为输入选择带引号的列我有以下的数据帧(tibble)如何使用dplyr
library(dplyr)
dat <- structure(list(`YY_164.XXX-ad` = c(0.004, 0, 0, 0.001, 0.001,
0.001), `YY_165.XXX-ad` = c(0.022, 0.001, 0, 0.001, 0.002, 0
), `YY_162.XXX-ad` = c(0.013, 0, 0, 0.001, 0.001, 0.001), `YY_163.XXX-ad` = c(0.023,
0, 0, 0.001, 0, 0.001), `YY_166.XXX-ad` = c(0.062, 0.001, 0.001,
0.001, 0.005, 0.001)), .Names = c("YY_164.XXX-ad", "YY_165.XXX-ad",
"YY_162.XXX-ad", "YY_163.XXX-ad", "YY_166.XXX-ad"), row.names = c(NA,
-6L), class = c("tbl_df", "tbl", "data.frame"))
dat
#> # A tibble: 6 x 5
#> `YY_164.XXX-ad` `YY_165.XXX-ad` `YY_162.XXX-ad` `YY_163.XXX-ad`
#> <dbl> <dbl> <dbl> <dbl>
#> 1 0.004 0.022 0.013 0.023
#> 2 0.000 0.001 0.000 0.000
#> 3 0.000 0.000 0.000 0.000
#> 4 0.001 0.001 0.001 0.001
#> 5 0.001 0.002 0.001 0.000
#> 6 0.001 0.000 0.001 0.001
#> # ... with 1 more variables: `YY_166.XXX-ad` <dbl>
我想要做的是基于矢量选择栏:
pp <- c('YY_164.XXX-ad','YY_165.XXX-ad')
我试过,但出现错误:
dat %>%
select_(pp)
#> Error in overscope_eval_next(overscope, expr): object 'YY_164.XXX' not found
怎样做正确的方式?