how to select certain columns in R
1
0
Entering edit mode
7.5 years ago
mms140130 ▴ 60

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 • 2.5k views
ADD COMMENT
2
Entering edit mode

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

ADD REPLY
0
Entering edit mode

Hello mms140130!

It appears that your post has been cross-posted to another site: https://support.bioconductor.org/p/97884/

This is typically not recommended as it runs the risk of annoying people in both communities.

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
5
Entering edit mode
7.5 years ago

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.

ADD COMMENT
0
Entering edit mode

Thank you very much , that was really helpful :)

ADD REPLY

Login before adding your answer.

Traffic: 1416 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