[R] Writing out data

Paul Hiemstra paul.hiemstra at knmi.nl
Thu Feb 2 13:43:26 CET 2012


On 02/02/2012 11:40 AM, Thomas wrote:
> What is the best way to write out comma separated data, as a program
> is running (rather than waiting to the end using write.csv)? At the
> moment I'm doing this, but I guess it's not the most efficient. The
> data is in a column in the matrix postcount, and I'm using a loop to
> write out each of the 100 elements.
>
> for (j in 1:100)
> {
> cat(postcount[1,j], ",", file=filename, append=TRUE)
> }
> cat("\n", file=filename, append=TRUE)
>
>
> Thank you!
>
> Thomas
>
> This message and any attachment are intended solely for the addressee
> and may contain confidential information. If you have received this
> message in error, please send it back to me, and immediately delete
> it.   Please do not use, copy or disclose the information contained in
> this message or in any attachment.  Any views or opinions expressed by
> the author of this email do not necessarily reflect the views of the
> University of Nottingham.
>
> This message has been checked for viruses but the contents of an
> attachment
> may still contain software viruses which could damage your computer
> system:
> you are advised to perform your own checks. Email communications with the
> University of Nottingham may be monitored as permitted by UK legislation.
>
> ______________________________________________
> 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.
Hi,

write.csv also supports an append argument. Maybe that is faster than
using cat.

cheers,
Paul

-- 
Paul Hiemstra, Ph.D.
Global Climate Division
Royal Netherlands Meteorological Institute (KNMI)
Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39
P.O. Box 201 | 3730 AE | De Bilt
tel: +31 30 2206 494

http://intamap.geo.uu.nl/~paul
http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770



More information about the R-help mailing list