Hi Thomas, If "x" contains your current results, one way to do what you want is the following:
# data x <- read.table(textConnection("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"), sep = ",") closeAllConnections() x # results data.frame(output = with(x, tapply(V2, V1, paste, sep = "", collapse = ','))) HTH, Jorge On Thu, Dec 2, 2010 at 11:00 PM, Thomas Parr <> wrote: > From: Thomas Parr [mailto:thomas.p...@maine.edu] > Sent: Thursday, December 02, 2010 10:52 PM > To: r-help-requ...@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 > > ______________________________________________ > R-help@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. > [[alternative HTML version deleted]] ______________________________________________ R-help@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.