I have written a code for removing columns from multiple text files.
file_list <- list.files(pattern = ".txt")
dfList <- lapply(file_list, function(f) {
df <- read.table(f, header=TRUE, sep="\t", stringsAsFactors=FALSE)
df <- df[grep("(adj.P.Val|P.Value|t|B)", names(df), invert = TRUE)]
})
finaldf <- do.call(rbind, dfList)
But i need multiple files as it is. rbind merges all the file. How to remove only columns from all the files keeping as it is? Thanks in advance
After the lapply command you should end up with a list of data.frames that each only have the selected columns. What did you want to do with this list exactly?
I want to remove columns from the files and keep it as it is.i want them separate only
So do you want to save them as new files then?
yes but all should be separate. not in one