This is a test version of Biostars. For the public version, visit https://www.biostars.org.
how to select certain columns in R

I have the following part of the data

      TCGA-3C-AAAU-01A-11D-A41E-01 TCGA-3C-AAAU-10A-01D-A41E-01
A1BG                           0.1302                       0.0064
A2M                            0.2586                       0.0033
A2MP1                          0.2586                       0.0033
NAT1                           0.2662                       0.0034
NAT2                           0.2662                       0.0034
SERPINA3                      -0.2761                       0.0034
         TCGA-3C-AALI-01A-11D-A41E-01
A1BG                           0.1036
A2M                            0.0309
A2MP1                          0.0309
NAT1                           0.3269
NAT2                           0.3269
SERPINA3                       0.0252

I want to select the columns that contain -01A- only , 4th place from the left

TCGA-3C-AALI-01A-11D-A41E-01

How can I do that ?

r

try to use "colnames, substr and which" functions in R

Please follow up on your previous questions. It's important to provide feedback.

If an answer was helpful you should upvote it, if the answer resolved your question you should mark it as accepted. Upvote|Bookmark|Accept

I will look at my previous Questions and provide feedback ! Thank you..

1 answer

This is a nice example of when the dplyr package is useful. Given a dataframe, d:

> library(dplyr)
> d %>% select(contains("-01A-")) # or just 'select(d, contains("-01A"))'

The will select all columns containing "-01A-" in the column name.

Thank you very much , that was really helpful :)

Log in to answer this question.