[R] format a matrix as fractions?

arun smartpink111 at yahoo.com
Tue Dec 31 16:32:18 CET 2013



library(MASS)
 fractions(outer(1/seq(1:3), 1/seq(1:3)))
#     [,1] [,2] [,3]
#[1,]   1  1/2  1/3 
#[2,] 1/2  1/4  1/6 
#[3,] 1/3  1/6  1/9 
A.K.


On Tuesday, December 31, 2013 10:27 AM, Michael Friendly <friendly at yorku.ca> wrote:
Is there some way to format a matrix of fractions as fractions?  I think 
I've seen this somewhere,
but search on Rseek came up empty.

Example:

> outer(1/seq(1:3), 1/seq(1:3))
           [,1]      [,2]      [,3]
[1,] 1.0000000 0.5000000 0.3333333
[2,] 0.5000000 0.2500000 0.1666667
[3,] 0.3333333 0.1666667 0.1111111
>

should print as

       1     1/2     1/3
     1/2    1/4     1/6
     1/3    1/6     1/9

TIA
-Michael

-- 
Michael Friendly     Email: friendly AT yorku DOT ca
Professor, Psychology Dept. & Chair, Quantitative Methods
York University      Voice: 416 736-2100 x66249 Fax: 416 736-5814
4700 Keele Street    Web:  http://www.datavis.ca
Toronto, ONT  M3J 1P3 CANADA

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




More information about the R-help mailing list