**R program to get all prime numbers up to a given number:** In this program, you will learn about R program to get all prime number.

A positive integer greater than 1 which has no other factors except 1 and the number itself is called a **prime number**.

Numbers **2, 3, 5, 7, 11, 13** etc.

## R Program to Check All Prime Numbers up to a Given Number

**Source Code**

```
prime_numbers <- function(n) {
if (n >= 2) {
x = seq(2, n)
prime_nums = c()
for (i in seq(2, n)) {
if (any(x == i)) {
prime_nums = c(prime_nums, i)
x = c(x[(x %% i) != 0], i)
}
}
return(prime_nums)
}
else
{
stop("Input number should be at least 2.")
}
}
prime_numbers(12)
```

**Output**