I have been looking at some 'table' examples in Peter Dalgaard's ISwR book, and I am confused by how to get right justification of my table headings when I use the tables() command. Compare the following: # Produces right justfified column names caff.marital=matrix(c(652,1537,598,242,36,46,38,21,218,327,106,67),nrow=3,byrow=T) colnames(caff.marital)=c("0","1-150","151-300",">300") rownames(caff.marital)=c("Married","Prev.married","Single") caff.marital class(caff.marital) #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.> version_ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 0.0 year 2004 month 10 day 04 language R ___________________________ Robert W. Baer, Ph.D. Department of Physiology A. T. Still University of Health Science 800 W. Jefferson St. Kirksville, MO 63501-1497 USA [[alternative HTML version deleted]]
"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
Robert W. Baer, Ph.D. wrote:> I have been looking at some 'table' examples in Peter Dalgaard's ISwR book, and I am confused by how to get right justification of my table headings when I use the tables() command. Compare the following: > > # Produces right justfified column names > caff.marital=matrix(c(652,1537,598,242,36,46,38,21,218,327,106,67),nrow=3,byrow=T) > colnames(caff.marital)=c("0","1-150","151-300",">300") > rownames(caff.marital)=c("Married","Prev.married","Single") > caff.marital > class(caff.marital) > > #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.[Since this question seems to be unanswered:] This is a question related to Peter Dalgaard's book, so why don't you ask the author rather than the whole world? Note that caff.materia is a matrix while as.table(caff.marital) is a table (and has a different print method). Why does the justification matter here? I'm much too lazy to look for changes in R related to your question - but probably you have done yourself before asking the question...??? And why don't you cite the example you are referring to (e.g. by a page number!!!) exactly? I'm also too lazy to read Peter's book once more just in order to find the example you are talking about! Uwe Ligges>>version > > _ > platform i386-pc-mingw32 > arch i386 > os mingw32 > system i386, mingw32 > status > major 2 > minor 0.0 > year 2004 > month 10 > day 04 > language R > > ___________________________ > Robert W. Baer, Ph.D. > Department of Physiology > A. T. Still University of Health Science > 800 W. Jefferson St. > Kirksville, MO 63501-1497 USA > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > [[alternative HTML version deleted]]