Question: select() not working in R
0
gravatar for j.lunger18
10 months ago by
j.lunger1810
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...

**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 • 555 views
ADD COMMENTlink modified 10 months ago by antonioggsousa1.3k • written 10 months ago by j.lunger1810

Or use base subset:

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

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 COMMENTlink written 10 months ago by antonioggsousa1.3k
Please log in to add an answer.

Help
Access

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