[R] How to export text into separate text files
John Kane
jrkrideau at yahoo.ca
Tue Oct 28 15:31:50 CET 2008
"jim holtman" <jholtman at gmail.com> just answered a similar question for someone who wanted to input txt files. His suggestion is below. It should work for output as well
Jim Holtman's suggestion.
-----------------------------------------------------------------
for (i in 2:4){
input <- read.delim(paste('vegetation_', i, '.txt', sep=''))
,,,, process the file ....
}
--------------------------------------------------
--- On Tue, 10/28/08, Lauri Nikkinen <lauri.nikkinen at iki.fi> wrote:
> From: Lauri Nikkinen <lauri.nikkinen at iki.fi>
> Subject: [R] How to export text into separate text files
> To: r-help at stat.math.ethz.ch
> Received: Tuesday, October 28, 2008, 10:26 AM
> Hello,
>
> I'm producing text from my data.frame using cat
> function. I would like
> to use for loop to export each column in my data.frame into
> separate
> text files. Here is the example code
>
> r <- t(Indometh)
> for (i in 1:ncol(r)) {
> cat("Some text,", "\n")
> cat("\n")
> cat("More text, More text, More text")
> cat("\n")
> cat(paste(names(r[!is.na(r[,i]), i]), ":",
> as.character(r[!is.na(r[,i]), i]), "\n"))
> cat("-----------------------------------",
> "\n")
> }
>
> So, each of these columns (results between --- and ---)
> should be
> exported into separate text files e.g. file1.txt,
> file2.txt, file3.txt
> etc.
>
> Any ideas?
>
> Thanks,
> Lauri
>
> ______________________________________________
> R-help at r-project.org 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.
More information about the R-help
mailing list