title: R: Format output of write.table
body: <p>Is it possible to format output with write.table?</p>
  
  <p>I can left-align columns using tab, <code>sep = '\t'</code>, and can increase spacing between columns using two tabs, <code>sep = '\t\t'</code>.</p>
  
  <p>Ideally I would like to be able to right-align columns and use an intermediate amount of spacing than that provided
  by '\t' and '\t\t'.  Using something like <code>sep = '\t  '</code> completely destroyes column alignment.</p>
  
  <p>I must proof a large amount of data extracted from many different files that use numerous different table formats.  Closely matching column spacing of R's output text files to that in the original pdf documents would substantially increase speed and accuracy of proofing.</p>
  
  <pre><code># example data to write to text file
  
  aa = matrix(c(1000,110,10,1, 
                0,2000,20,2, 
                30,300,3000,30000), nrow=3, byrow=TRUE,
           dimnames = list(NULL, c("C1", "C2", "C3","C4")))
  aa
  
  # left align columns using a tab
  
  write.table(aa,file="c:/users/mark w miller/simple r programs/formatted_tablea.txt", na = 'NA', sep = '\t',
  row.names = F, col.names = F)
  
  #   1000    110 10  1
  #   0   2000    20  2
  #   30  300 3000    30000
  
  # increase spacing between columns with two tabs
  
  write.table(aa,file="c:/users/mark w miller/simple r programs/formatted_tableb.txt", na = 'NA', sep = '\t\t',
  row.names = F, col.names = F)
  
  #   1000        110     10      1
  #   0       2000        20      2
  #   30      300     3000        30000
  
  # Here is an example of the desired right-aligned output 
  # format with an intermediate amount of spacing 
  # (3 spaces vs the 1 or 7 spaces used above):
  
  #   1000    110     10       1
  #      0   2000     20       2
  #     30    300   3000   30000
  
  # Maybe use cat somehow? 
  
  cat(file="c:/users/mark w miller/simple r programs/formatted_tablec.txt", aa, sep=c(' ', ' ', '\n'))
  </code></pre>
  
  <p>Or must I write to a csv file and open the output file with Excel?  I would prefer to avoid Excel.  Or perhaps I must create the output data in the desired format using LaTex?</p>
  
  <p>Sorry for all of the questions this week.</p>