[R] cancelling in fraction
Greg Snow
Greg.Snow at imail.org
Fri Apr 23 17:42:00 CEST 2010
Here is a different approach that may work for you, or give you a starting place:
> library(MASS)
> fractions(60/(220*6))
[1] 1/22
Hope this helps,
--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of capybara!
> Sent: Friday, April 23, 2010 7:49 AM
> To: r-help at r-project.org
> Subject: [R] cancelling in fraction
>
>
> Dear All,
>
> I have a fraction of 60./(220.*6.), which equals 1./22.
> My question is how to cancel the fraction so I actually get 1/22
> (actually I
> just need the factor 22) using R. I tried it with prime factor
> decomposition
> from the package "schoolmath":
>
> > require("schoolmath")
> Loading required package: schoolmath
> > nom <- prime.factor(60)
> > nom
> [1] 2 2 3 5
> > denom <- prime.factor(220 * 6)
> > denom
> [1] 2 2 2 3 5 11
>
> So far so good, now I just need to take all elements which are in nom
> out of
> denom (if possible).
> For this I use the package "sets", its function set_complement should
> exactly do that, but:
>
> > require(sets)
> > set_complement(nom, denom)
> {2, 2, 11}
>
> It gives me {2,2,11} and 2 * 2 * 11 is 44 and not 22.
> What am I doing wrong? Can anybody help me?
> Is there maybe a more elegant way to cancel a fraction than by prime
> factor
> decomposition?
>
> Many thanks in advance,
>
> Hannes
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/cancelling-
> in-fraction-tp2062218p2062218.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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