[R] Problems trying to generate a prime factor vector
Franklin Bretschneider
bretschr at xs4all.nl
Thu Dec 3 14:29:46 CET 2015
Hi Kevin Wright,
Re:
>
> I am very new to 'R' and am trying to write an R function which returns the
> prime factors of a given number(n)
>
> Unfortunately, the function only works for very small numbers, if for
> example I pass 18 to the function
> a mysteriously long vector is returned. I have not been able to find where
> or why this is happening.
> I know I've done something wrong. I've tried using debugging statements.
> Sometimes the
> currentPrime variable seems to become some sort of array?!
>
>
> can you help?
>
>
> library(gmp)
>
But why writing one? Such a function is already in gmp: factorize(n), and
it works with fairly large numbers:
>library(gmp)
>factorize(12345678987654321)
Big Integer ('bigz') object of length 13:
[1] 2 2 2 2 5 7 11 73 101 109 109 137 167
Success,
Frank
------
Franklin Bretschneider
Dept of Biology
Utrecht University
bretschr at xs4all.nl
More information about the R-help
mailing list