[R] Matrix/Table col headings R 2.0.0

Peter Dalgaard p.dalgaard at biostat.ku.dk
Tue Oct 19 21:39:35 CEST 2004


"Robert W. Baer, Ph.D." <rbaer at atsu.edu> writes:

> #Produces Left justified column names
> library(ISwR)
> data(juul)
> attach(juul)
> sex.tan=table(sex,tanner)
> colnames(sex.tan)=c("I","II","IIII","IV","V")
> rownames(sex.tan)=c("M","F")
> sex.tan
> class(sex.tan)
> 
> # Finally, look at (left justified)
> as.table(caff.marital)
> 
> Somehow PD got right justified columns with this dataset. Is there a
> new way of doing things in version 2.0.0, my ignorance, a bug? I
> tried making the columns factors first, but in my hands this did not
> appear to help either. Thanks for any insight.

The book (which by the way does not have an example involving
"sex.tan" anywhere, but does have an example with the tranposed table)
is based on R 1.5.0 which was current in early 2002. I have check runs
done on October 1, 2002 with right justified labels, so I suppose this
got changed in between.

The label justification comes from printing of the character matrix
created by format() inside print.table(), so

   print(sex.tan, right=T)

gives you what you want.

The fundamental issue seems to be that we get left-justified printing
of strings that contains right-justified text. The effect is quite
clear in

> format(unclass(table(sex,tanner)))
   tanner
sex 1     2     3     4     5
  1 "291" " 55" " 34" " 41" "124"
  2 "224" " 48" " 38" " 40" "204"


-- 
   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