[R] Adding dash-lines in R tables

David Winsemius dwinsemius at comcast.net
Sun May 22 15:52:41 CEST 2011


On May 22, 2011, at 7:47 AM, Axel Urbiz wrote:

> is it possible to add dash lines to tables or matrices when they are
> printed? An example of what I'm looking for is this:
>
> library(Design)
> y <- sample(c(0,1),100, replace = TRUE)
> x <- rnorm(100)
> summary(y ~ x)

There is a method for summary on formula objects found by typing

methods(summary)   # didn't find the answer looking at code of  
summary.formula.

Then there is a print method for summary.formula objects>

methods(print)
# examine the 3 print.summary. .... methods
# didn't find the answer there, either, but did notice that the
# function `print.char.matrix` was being used near the end of the code

 > M <- matrix(letters[1:10], 2)
 > print.char.matrix(M)
+-+-+-+-+-+
|a|c|e|g|i|
+-+-+-+-+-+
|b|d|f|h|j|
+-+-+-+-+-+

It is in package Hmisc and its behavior is documented:

?print.char.matrix

 > print.char.matrix( table(sample(1:10, 100, replace=TRUE) )  )
+--+--+
| 1|12|
+--+--+
| 2| 6|
+--+--+
| 3|11|
+--+--+
| 4|13|
+--+--+
| 5|12|
+--+--+
| 6| 7|
+--+--+
| 7| 8|
+--+--+
| 8| 8|
+--+--+
| 9|14|
+--+--+
|10| 9|
+--+--+

-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list