On Tue, 13 Oct 2009, 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?

It depends a bit on how big the numbers are. If the array is large but the numbers are not very large the fastest approach is probably to create a vector of small primes and use
   my_array %in% smallprimes.

For example, the first 1000 primes are at 
http://primes.utm.edu/lists/small/1000.txt
and the first 10000 are on the same site.


      -thomas

Thomas Lumley                   Assoc. Professor, Biostatistics
tlum...@u.washington.edu        University of Washington, Seattle

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to