chandu wrote: > > I am relatively new to R. I would like to know how can we write the > realizations (for example generated through rnorm or runif) in to a data > file. It would be very inefficient to first generate values and then write > them in to file using "write" function. Instead, is there a way to > generate 1 value at a time and append them in to the file. >
"It would be very inefficient". Sounds like you tried it. n = 30000 system.time(for (i in 1:n){ cat(rnorm(1),file="a.txt",append=TRUE) } ) system.time(write.table(rnorm(n),file="b.txt")) ) user system elapsed 3.98 8.66 16.11 > system.time(write.table(rnorm(n),file="b.txt")) user system elapsed 0.59 0.01 0.61 So the inefficient method is about 25 times faster. Dieter -- View this message in context: http://r.789695.n4.nabble.com/writing-sample-values-in-to-a-file-tp3086286p3087354.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.