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.
Writing out data
4 messages · Thomas Friedrichsmeier, Paul Hiemstra, Ivan Calandra +1 more
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
Correct me if I'm wrong, but I think that write.csv() doesn't have an append argument; write.table() does though. Ivan -- Ivan CALANDRA Universit? de Bourgogne UMR CNRS/uB 6282 Biog?osciences 6 Boulevard Gabriel 21000 Dijon, FRANCE +33(0)3.80.39.63.06 ivan.calandra at u-bourgogne.fr Le 02/02/12 13:43, Paul Hiemstra a ?crit :
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
I believe connections were designed to do this as efficiently as possible by keeping the i/o path "open" rather than reopening it each time like write.table(append = TRUE) would do, though I may be wrong on the details: see ?connections. Prof Ripley has a good article about them in R News 1.1 -- http://cran.r-project.org/doc/Rnews/Rnews_2001-1.pdf -- but it's a rather out of date. Michael On Thu, Feb 2, 2012 at 7:56 AM, Ivan Calandra
<ivan.calandra at u-bourgogne.fr> wrote:
Correct me if I'm wrong, but I think that write.csv() doesn't have an append argument; write.table() does though. Ivan -- Ivan CALANDRA Universit? de Bourgogne UMR CNRS/uB 6282 Biog?osciences 6 Boulevard Gabriel 21000 Dijon, FRANCE +33(0)3.80.39.63.06 ivan.calandra at u-bourgogne.fr Le 02/02/12 13:43, Paul Hiemstra a ?crit :
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
______________________________________________ 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.