[R] xtable with a table ?

Peter Dalgaard p.dalgaard at biostat.ku.dk
Tue May 11 17:08:22 CEST 2004


"Ian Wilson" <I.Wilson at maths.abdn.ac.uk> writes:

> Any more elegant solutions to this?
> 
> > a <- sample(c("a","d","c"),100,replace=T)
> > b <- sample(c("d","e","f",100,replace=T)
> > t <- table(a,b)
> > xtable(t)
> Error in xtable(t) : no applicable method for "xtable"


Others might get a different error:

> xtable(t)
Error: couldn't find function "xtable"
> library(xtable)
Error in library(xtable) : There is no package called 'xtable'


I.e. do remember to say when you're using a contributed package (and
also which version)

> After a horrible solution, I have 
> ct <- apply(t,2,cbind);
> rownames(ct) <- rownames(t);
> xtable(ct)
> 
> Is this a bug/feature, and if so how do I get round it?

I got away with 

 xtable(unclass(tb))

but of course there ought to be an xtable.table method. You still lose
the dimname-names though.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list