Skip to content

iterative output to file by row

2 messages · Christina Yau, Marc Schwartz

#
On Mon, 2005-10-10 at 17:04 -0700, Christina Yau wrote:
If you can do it with the full dataset, you are probably better off
using subset() to select the rows that meet your criteria and then use
write.table() to write the resultant smaller data frame to a file.

Alternatively, if you do need to do this within the loop, you can use
write.table() with the 'append' argument set to TRUE, so that each new
row from the data frame that meets your criteria gets added to the
existing file, rather than overwriting it. This will be a little slower,
since each time write.table() is called, it opens the file, writes the
line and closes the file, so there is some file I/O overhead.

You don't need to create a new matrix in the loop, just pass the
resultant single row of your subsetting operation to write.table().

See ?subset and ?write.table for more information.

HTH,

Marc Schwartz