Learn R Programming

spuRs (version 2.0.2)

primesieve: Function to identify all the primes in a vector of positive integers.

Description

This function uses the Sieve of Eratosthenes to find all the primes less than or equal to a given integer.

Usage

primesieve(sieved, unsieved)

Arguments

sieved

Identified primes (empty vector for initialization)

unsieved

Candidate integers

Value

Returns a vector of primes sieved (selected) from the input vector.

Details

The function assumes that unsieved is a vector of positive integers.

References

Jones, O.D., R. Maillardet, and A.P. Robinson. 2009. An Introduction to Scientific Programming and Simulation, Using R. Chapman And Hall/CRC.

See Also

prime

Examples

Run this code
# NOT RUN {
primesieve(c(), 2:200)

# }

Run the code above in your browser using DataLab