select() not working in R
1
0
Entering edit mode
5.1 years ago
j.lunger18 ▴ 30

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...

**head(mt_coding_variants[1:3])
# 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()
<error/rlang_error>
Unknown columns `A`, `A`, `A`, `A`, `C` and ... 
Backtrace:
 1. dplyr::select(mt_coding_variants, mt_coding_variants$REF)
 2. dplyr:::select.data.frame(mt_coding_variants, 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 • 3.4k views
ADD COMMENT
0
Entering edit mode

Or use base subset:

x <- mt_coding_variants[, "REF" ]
ADD REPLY
1
Entering edit mode
5.1 years ago

Hi,

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.

António

ADD COMMENT

Login before adding your answer.

Traffic: 1617 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6