Question: select() not working in R
gravatar for j.lunger18
3 months ago by
j.lunger1810 wrote:

Trying to make a new dataframe with a subset of columns in an existing dataframe. This worked for me before, not sure what's going wrong now...

# A tibble: 6 x 3
        POS ID          REF  
      <int> <chr>       <chr>
1 119606751 rs751351167 A    
2 119606751 rs751351167 A    
3 119606751 rs751351167 A    
4 119606751 rs751351167 A    
5 119609095 rs747135103 C    
6 119609095 rs747135103 C    
> x <- select(mt_coding_variants, mt_coding_variants$REF)
Error: Unknown columns `A`, `A`, `A`, `A`, `C` and ... 
Call `rlang::last_error()` to see a backtrace.
> rlang::last_error()
Unknown columns `A`, `A`, `A`, `A`, `C` and ... 
 1. dplyr::select(mt_coding_variants, mt_coding_variants$REF)
 2., mt_coding_variants$REF)
 3. tidyselect::vars_select(tbl_vars(.data), !!!enquos(...))
 4. tidyselect:::vars_select_eval(.vars, quos)
 5. purrr::map_if(ind_list, is_character, match_strings, names = TRUE)
 6. purrr::map(.x[sel], .f, ...)
 7. tidyselect:::.f(.x[[i]], ...)
 8. tidyselect:::bad_unknown_vars(vars, unknown)**
R • 153 views
ADD COMMENTlink modified 3 months ago by antonioggsousa90 • written 3 months ago by j.lunger1810

Or use base subset:

x <- mt_coding_variants[, "REF" ]
ADD REPLYlink written 3 months ago by zx87549.0k
gravatar for antonioggsousa
3 months ago by
antonioggsousa90 wrote:


select() is a method to select a column based on their name, ie, column name, and you are indexing the column. So, just do:

x <- select(mt_coding_variants, REF)

This is enough to select your column.


ADD COMMENTlink written 3 months ago by antonioggsousa90
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1113 users visited in the last hour