Combining the common elements in two lists in R, using only logical and arithmetic operators -
i'm attempting work out gcd of 2 numbers (x , y) in r. i'm not allowed use loops or if, else, ifelse statements. i'm restricted logical , arithmetic operators. far using code below i've managed make lists of factors of x , y.
xfac<-1:x xfac[x%%fac==0]
this gives me 2 lists of factors i'm not sure go here. there way can combine common elements in 2 lists , return greatest value?
thanks in advance.
yes, max(intersect(xfac,yfac))
should give gcd.
Comments
Post a Comment