[R] Table with n(%) formatting: A better way to do this?

Duncan Murdoch murdoch.duncan at gmail.com
Thu Apr 11 15:13:04 CEST 2013


On 11/04/2013 8:40 AM, Paul Miller wrote:
> Hello Dr. Murdoch,
>
> Thanks for your reply. Your tables package is interesting. Spent some time experimenting with it yesterday and it looks like something I can use.
>
> The n(%) format seems to be the standard for what I'm doing. So I can't directly use the output your package produces. It does provide something close to what I need though. So I can just write a little more code to get the n(%) formatting.
>
> Not sure how many others might need n(%) formatting. Think it could be quite a lot though. If so, that might be something you could consider adding to your tables package.

I don't think n(%) defines the format, there are still a lot of 
choices.  How many decimal places on the percent?  How do the n and % 
values align?  Is there space between them?  Do the parens align from 
row to row, or do they adjust to the length of the percent values?

Each user who wants this will need to answer those questions, and will 
answer them differently.  It's easy to write a little format function to 
implement any particular choice, but hard to write one that would 
satisfy everybody.

One thing that I would consider is an odf output driver (i.e. it outputs 
XML according to the odf spec).  Then you could use tables together with 
odfWeave.  I think that would be a relatively straightforward job, 
though it would probably end up being a couple of hundred lines of 
code.  Similarly, an HTML output driver could be useful.

Duncan Murdoch



More information about the R-help mailing list