[R] Prime Factorization

Hans W Borchers hwborchers at googlemail.com
Tue Sep 21 21:41:43 CEST 2010


David Winsemius <dwinsemius <at> comcast.net> writes:

> 
> On Sep 21, 2010, at 11:33 AM, Cliff Clive wrote:
> 
> >
> > Hi everyone, I have a very quick question:
> >
> > Is there a ready-made function in R or any R packages to find the  
> > prime
> > factorization of an integer?
> 
> Yes. At least two. The obvious search strategy with your favrite  
> search tool should work well.
>

I don't know which prime factorization functions David means --- sometimes
these search tips are quite a mystery to me.

You didn't tell us an important parameter, namely the size of integers you
want to factorize. For larger numbers there is just one such function that
can be taken into consideration, i.e. factorize() in the multiple precision
package 'gmp'.

    library(gmp)
    factorize(2^32+1)
    # [1] "641"     "6700417"

And better do not use the 'schoolmath' package, this package is of very low
quality and probably should be removed from CRAN.

Hans Werner



More information about the R-help mailing list