[R] Function to find prime numbers
Romain Francois
romain.francois at dbmail.com
Tue Oct 13 10:44:47 CEST 2009
On 10/13/2009 09:59 AM, AJ83 wrote:
>
>
> I need to create a function to find all the prime numbers in an array. Can
> anyone point me in the right direction?
> Thank you.
> AJ
There is isprime in package gmp.
> data.frame( number = 1:10, is.prime = isprime( 1:10 ) > 1,
is.probably.prime = isprime(1:10) > 0 )
number is.prime is.probably.prime
1 1 FALSE FALSE
2 2 TRUE TRUE
3 3 TRUE TRUE
4 4 FALSE FALSE
5 5 TRUE TRUE
6 6 FALSE FALSE
7 7 TRUE TRUE
8 8 FALSE FALSE
9 9 FALSE FALSE
10 10 FALSE FALSE
See this: http://jostamon.blogspot.com/2009/02/goldbachs-comet.html for
an example of its use.
Romain
--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/BcPw : celebrating R commit #50000
|- http://tr.im/ztCu : RGG #158:161: examples of package IDPmisc
`- http://tr.im/yw8E : New R package : sos
More information about the R-help
mailing list