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

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

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.

1 answer

Meth %>% dplyr::select(-c(DF$x))

thanks , I did this and it also works.

 extracted <- datMeth[,!(colnames(datMeth) %in% DF$x)]

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

Log in to answer this question.