how to remove multiple columns from a file in R
1
0
Entering edit mode
11 months ago
Bioinfonext ▴ 470

Hi all,

Could anyone please help how to remove col names from Meth file which are present in DF file.

DF <- read.table("DIFF.txt", as.is=T, na.strings="NA", check.names=FALSE)
head(DF)
            x
1 NSE.1.0096
2 NSE.1.0100
3 NSE.1.0121


library(readr)
Meth <- read_csv("betas_1.csv", col_types = cols(Chromosome = col_skip())

head(Meth, 10) [,1:5]
    A tibble: 10 × 5
       ID         NSE.1.0093 NSE.1.0095 NSE.1.0096 NSE.1.0097
       <chr>            <dbl>       <dbl>       <dbl>       <dbl>
     1 cg26928153      0.939       0.941       0.923       0.924 
     2 cg16269199      0.900       0.902       0.853       0.872 
     3 cg13869341      0.936       0.926       0.856       0.924 
     4 cg24669183      0.898       0.901       0.957       0.864
r • 694 views
ADD COMMENT
0
Entering edit mode

Please stop asking basic R/programming questions and use Google to learn the underlying concepts. A simple search is the way to start: https://www.google.com/search?q=r+dataframe+exclude+columns

Also, your code is not reproducible - You read data into Meth and then select columns from datMeth.

ADD REPLY
2
Entering edit mode
11 months ago
Trivas ★ 1.8k
Meth %>% dplyr::select(-c(DF$x))
ADD COMMENT
1
Entering edit mode

thanks , I did this and it also works.

 extracted <- datMeth[,!(colnames(datMeth) %in% DF$x)]
ADD REPLY
0
Entering edit mode

Accept their answer and then add your own and accept that as well.

ADD REPLY

Login before adding your answer.

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