[R] Writing to a file

Thomas Parr thomas.parr at maine.edu
Fri Dec 3 05:00:04 CET 2010


From: Thomas Parr [mailto:thomas.parr at maine.edu] 
Sent: Thursday, December 02, 2010 10:52 PM
To: r-help-request at stat.math.ethz.ch
Subject: Writing to a file

I am trying to get my script to write to a file from the for loop.  It is
"working", but the problem is at it is outputting to two columns and I want
it to output to 5.  

Current results
X2403,0.006049271
X2403,0.000118622
X2403,50.99600705
X2403,7.62E-150
X2419,0.012464215
X2419,9.07E-05
X2419,137.4022573
X2419,6.45E-273
...

Desired/expected results
X2403,0.0060492710.000118622,50.99600705,7.62E-150
X2419,0.012464215,9.07E-05,137.4022573,6.45E-273
...

Data is being extracted from "nls" output with "summary", "nls" uses "fit."

a<-summary(nls(acoeff ~ aref*exp(-S*(alam-375)), trace=T,
start=list(S=0.0015)))
cat(sites[v-1],a$coefficients[1,1],a$coefficients[1,2],a$coefficients[1,3],a
$coefficients[1,4],sep=",",append=TRUE,
file=paste(dirpath,"/results.csv",sep=""))

The idea is that it is looping through the data sites and as "nls" generates
parameter estimates, "summary" extracts them and "cat" writes them to a CSV
file.
Note: have tried write.csv, write.table, and write  I thing they all call
"cat" at some point.

Any help would be appreciated and if you have a different solution I am all
ears.

Thomas



More information about the R-help mailing list