[R] cancelling in fraction

David Winsemius dwinsemius at comcast.net
Fri Apr 23 18:38:23 CEST 2010


And even then I'm guessing the the set complement of  {2,2,2, 3,5,11}  
with {2,2, 11} should not be {2, 3, 3}  .... if R's versions of sets  
works the way I was taught in high school, anyway.

 > x <-set(2,2,2, 3,5,11) ; y <-set(2,2, 11)
 > x
{2, 3, 5, 11}   # because {2,2} == {2} in set theory
 > y
{2, 11}
 > set_complement(y,x)
{3, 5}

-- 
David.

On Apr 23, 2010, at 12:19 PM, Peter Ehlers wrote:

> Greg has provided a solution. Just to answer the question of
> why set_complement() is not doing what you think it should:
>
> You need to change your *vectors* nom and denom to *sets*
> with as.set().
>
> -Peter Ehlers
>
> On 2010-04-23 9:42, Greg Snow wrote:
>> 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
>
>>> >  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 guidehttp://www.R-project.org/posting-
>>> >  guide.html
>>> >  and provide commented, minimal, self-contained, reproducible  
>>> code.
>> ______________________________________________
>> R-help at r-project.org  mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>
> -- 
> Peter Ehlers
> University of Calgary
>
> ______________________________________________
> 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list