[R] Adding dash-lines in R tables
Ista Zahn
izahn at psych.rochester.edu
Sun May 22 17:23:12 CEST 2011
Axel, you may also be interested in the ascii function (in the ascii
package). The ascii version of David's example is
library(ascii) #may need install.packages("ascii") first
ascii(M)
ascii(table(sample(1:10, 100, replace=TRUE)))
Best,
Ista
On Sun, May 22, 2011 at 9:52 AM, David Winsemius <dwinsemius at comcast.net> wrote:
>
> 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
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org
More information about the R-help
mailing list