Question: (Closed) Applying a task to several files in R
0
gravatar for viniciushs88
4.9 years ago by
viniciushs8850
Germany
viniciushs8850 wrote:

I would to apply a loop in R to process several files, one file per time. The files have exactly the same pattern, just the string "...split1..." is a crescent number to my files. Then a have files like "...split1...", "...split2..." ... "...split777...". I want output files like in the same logic, in the example: "newsplit1.txt", "newsplit2.txt" ... "newsplit777.txt".

all <- read.table("nsamplescluster.split1.adjusted", header=TRUE, sep=";") all <- all[, -grep("GType", colnames(all))] write.table(all, "newsplit1.txt", sep=";")

Cheers!

lapply sapply loop R • 2.4k views
ADD COMMENTlink modified 4.9 years ago by Chris Miller20k • written 4.9 years ago by viniciushs8850

This doesn't have any connection to bioinformatics, right?

ADD REPLYlink written 4.9 years ago by Michael Dondrup45k

As Michael suggested, please make this relevant to bioinformatics or we'll just delete it. As is, this is more appropriate for stackoverflow or an R forum.

ADD REPLYlink written 4.9 years ago by Devon Ryan88k

I'm closing this up, since it's not a bioinformatics question, as noted below. This allow us to keep the site focused on the topics that the community can help with.  Please consider asking your question on Stack Overflow, or better yet, taking a little time to work through a basic R tutorial, which will help with both of the questions you've asked today.

ADD REPLYlink modified 4.9 years ago • written 4.9 years ago by Chris Miller20k
1
gravatar for Chris Miller
4.9 years ago by
Chris Miller20k
Washington University in St. Louis, MO
Chris Miller20k wrote:

here's some example code

> files = Sys.glob("*.txt")
> files
[1] "1.txt"     "2.txt"     "3.txt"
> for(i in files){
  #your code here
}

Now I'm closing this up, since it's really a programming question and not a bioinformatics question.  Based on your last two questions, you would benefit from working through a short R tutorial.

ADD COMMENTlink written 4.9 years ago by Chris Miller20k
Please log in to add an answer.
The thread is closed. No new answers may be added.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1022 users visited in the last hour