This looks like a problem to be solved long before a *write.table command.
We need to see some sample raw data and the output data. Some code would also be useful.