[R] Read multiple text files and combine into single file?

jim holtman jholtman at gmail.com
Wed Jan 31 14:32:25 CET 2007


I think something like this should work:

outFile <- file("output.txt", "w")
for (i in ListOfFileNames){
    x <- readLines(i)
    writeLines(x[2:(length(x)-1)], outFile)
}
close(outFile)



On 1/30/07, pif pif <pifbugs at hotmail.fr> wrote:
> Hi everyone!
>
> I have 1000 text files that contain data in a standard format separated by
> semi colons. However, each file also has single header (first) and footer
> (final) lines.  The text files are all named with a sample number, which do
> not follow a pattern.  I need to delete the header and footer lines and
> combine all files into a single (or possibly several) large files.
> Does anyone know how this could be done automatically using R?
>
> best regards,
>
> Ton
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list