1

How do you create a vector containing the first 5 prime numbers in R using a while loop?

Correct Answer: primes <- numeric(5); num <- 2; while (length(primes) < 5) { if (all(num %% 2:(num-1) != 0)) { primes <- c(primes, num) } num <- num + 1 }

Make the most of this question

This page focuses on one R Programming MCQs question from Programming. After checking the answer, return to the topic list to practice more or run a timed set.

R Programming MCQs MCQ: How do you create a vector containing the first 5 prime numbers in R using a while loop? | Extra Education