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
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.
I find that google is usually a better search engine for R topics Google on "R fractions". (I got, e.g. http://stackoverflow.com/questions/5046026/print-number-as-reduced-fraction-in-r ) -- Cheers, Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." H. Gilbert Welch On Tue, Dec 31, 2013 at 7:25 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.