[R] Tables package - remove NAs and NaN
Liviu Andronic
landronimirc at gmail.com
Tue Apr 23 11:04:12 CEST 2013
Dear David,
On Tue, Apr 23, 2013 at 10:00 AM, David Winsemius
<dwinsemius at comcast.net> wrote:
> tabular( (`p a`=interaction(a,p, drop=TRUE, sep=" ")) ~ (N = 1) + (b + c)*
> (mean+sd),data=q)
>
> b c
> p a N mean sd mean sd
> 1 A 10 12.8 0.7888 52.1 8.020
> 3 A 10 14.6 3.7771 56.5 6.980
> 2 B 10 16.3 3.0569 54.9 8.711
>
>
Unfortunately although this works, with this approach the formatting
completely breaks down. Consider the following slightly modified
example:
##generate longer labels
q <- data.frame(p=rep(c("First group","Second group"),each=10,len=30),
a=rep(c("Some long label","Some other long label",
"Yet another label"),each=10),id=seq(30),
b=round(runif(30,10,20)),
c=round(runif(30,40,70)))
##formatting OK (use monospace font)
tabular(((p=factor(p))*(a=factor(a))+1) ~ (N = 1) + (b + c)*
(mean+sd),data=q)
p a N mean sd mean sd
First group Some long label 10 12.6 1.897 58.4 9.204
Some other long label 0 NaN NA NaN NA
Yet another label 10 15.6 3.373 55.8 7.671
Second group Some long label 0 NaN NA NaN NA
Some other long label 10 14.1 2.183 58.3 8.551
Yet another label 0 NaN NA NaN NA
All 30 14.1 2.771 57.5 8.291
##formatting broken (use monospace font)
tabular( (`a p`=interaction(a,p, drop=TRUE, sep=" ") +1) ~ (N = 1) + (b + c)*
(mean+sd),data=q)
b c
a p N mean sd mean sd
Some long label First group 10 12.6 1.897 58.4 9.204
Yet another label First group 10 15.6 3.373 55.8 7.671
Some other long label Second group 10 14.1 2.183 58.3 8.551
All 30 14.1 2.771 57.5 8.291
Unfortunately this last table is unreadable. Is there a way to work
around this issue? Maybe we could use tab as separators, but
interaction(a,p, drop=TRUE, sep="'\t") didn't do what I had hoped.
Regards,
Liviu
More information about the R-help
mailing list