Re: [R] All the products of common factors

2009-02-25 Thread Stavros Macrakis
On Wed, Feb 25, 2009 at 9:25 AM, Fox, Gordon g...@cas.usf.edu wrote: The tricky part isn't finding the common factors -- we knew how to do that, though not in so concise a fashion as some of these suggestions. It was finding all their products without what I (as a recovered Fortran programmer)

Re: [R] All the products of common factors

2009-02-25 Thread Gordon Fox
Sorry - I didn't express myself very clearly. Yes, we're looking for common factors of A and B. One way to get there is by my initial approach: find the prime factors of each, select those that are in common, and then take pairwise products. My initial question was about the last step only.

Re: [R] All the products of common factors

2009-02-24 Thread Ben Bolker
Fox, Gordon gfox at cas.usf.edu writes: Example: 40 and 80 have these factors: c(1,2,2,2,5) and c(1,2,2,2,2,5). We can use match() to get the common factors c(1,2,2,2,5). What we want to be able to get from this is the list of all the possible products, which should be the concatenation of

Re: [R] All the products of common factors

2009-02-24 Thread Jorge Ivan Velez
Dear Gordon, Try also, unique(apply(expand.grid(commfac,commfac),1,prod)) [1] 1 2 5 4 10 25 HTH, Jorge On Mon, Feb 23, 2009 at 9:52 PM, Fox, Gordon g...@cas.usf.edu wrote: This is a seemingly simple problem - hopefully someone can help. Problem: we have two integers. We want (1) all

Re: [R] All the products of common factors

2009-02-24 Thread Stavros Macrakis
On Mon, Feb 23, 2009 at 9:52 PM, Fox, Gordon g...@cas.usf.edu wrote: This is a seemingly simple problem - hopefully someone can help. Problem: we have two integers. We want (1) all the common factors, and (2) all the possible products of these factors. We know how to get (1), but can't figure

Re: [R] All the products of common factors

2009-02-24 Thread Stavros Macrakis
L'esprit de l'escalier strikes again An even simpler statement of your original problem: Find the factors that A and B have in common. If A and B are fairly small ( 1e7, say), a very direct approach is: which( ! (A %% 1:min(A,B)) !(B %% 1:min(A,B)) ) Is this brute force?