Learn R Programming

primes (version 1.6.0)

next_prime: Find the Next and Previous Prime Numbers

Description

Find the next prime numbers or previous prime numbers over a vector.

Usage

next_prime(x)

prev_prime(x)

Value

An integer vector of prime numbers.

Arguments

x

a vector of integers from which to start the search.

Author

Paul Egeler, MS

Details

For prev_prime, if a value is less than or equal to 2, the function will return NA.

Examples

Run this code
next_prime(5)
## [1] 7

prev_prime(5:7)
## [1] 3 5 5

Run the code above in your browser using DataLab