R Programming MCQs with answers Page - 119

Here, you will find a collection of MCQ questions on R Programming. Go through these questions to enhance your preparation for upcoming examinations and interviews.

To check the correct answer, simply click the View Answer button provided for each question.

Have your own questions to contribute? Click the button below to share your MCQs with others!

+ Add Question

A

Admin • 833.24K Points
Coach

Q. Point out the correct statement?

  • (A) R has a number of ways to indicate to you that something's not right
  • (B) Executing any function in R may result in the condition
  • (C) "condition" is a generic concept for indicating that something unexpected has occurred
  • (D) All of the mentioned

A

Admin • 833.24K Points
Coach

Q. What will be the output of the following R code?
> x <- c("a", "b", "c", "d")
> for(i in 1:4) {
+ ## Print out each element of 'x'
+ print(x[i])
+ }

  • (A) [1] "a" [1] "b" [1] "c" [1] "d"
  • (B) [1] "c" [1] "b" [1] "a" [1] "d"
  • (C) [1] "d" [1] "c" [1] "b" [1] "a"
  • (D) Error

A

Admin • 833.24K Points
Coach

Q. Point out the wrong statement?

  • (A) A formal argument can be a symbol, a statement of the form 'symbol = expression', or the special formal argument
  • (B) The first component of the function declaration is the keyword function
  • (C) The value returned by the call to function is not a function
  • (D) Functions are also often written when code must be shared with others or the public

A

Admin • 833.24K Points
Coach

Q. What is the output of the following R code: for (i in 1:5) { if (i == 3) next; print(i) }

  • (A) 1, 2, 4, 5
  • (B) 1, 2, 3, 4, 5
  • (C) 2, 4
  • (D) 0, 1, 2, 3, 4

A

Admin • 833.24K Points
Coach

Q. Which control structure in R is used to execute a block of code repeatedly until a condition is met?

  • (A) if-else loop
  • (B) for loop
  • (C) while loop
  • (D) do-while loop

A

Admin • 833.24K Points
Coach

Q. In R, what is the purpose of the if-else statement?

  • (A) To execute a block of code if a condition is true, otherwise execute another block of code
  • (B) To create a loop that iterates a specified number of times
  • (C) To check multiple conditions sequentially
  • (D) To execute a block of code repeatedly until a condition is met

A

Admin • 833.24K Points
Coach

Q. How is the switch() function used in R?

  • (A) To toggle between TRUE and FALSE values
  • (B) To switch the positions of two elements
  • (C) To select one of several alternatives
  • (D) To change the direction of a loop

A

Admin • 833.24K Points
Coach

Q. In R, what is the syntax for the for loop?

  • (A) for (i in 1:10) { code_block }
  • (B) for (i = 1 to 10) { code_block }
  • (C) for (i = 1; i <= 10; i++) { code_block }
  • (D) for (i from 1 to 10) { code_block }

A

Admin • 833.24K Points
Coach

Q. What is the purpose of the break statement in a loop in R?

  • (A) To exit the loop immediately
  • (B) To skip the current iteration of the loop
  • (C) To restart the loop from the beginning
  • (D) To increment the loop variable

A

Admin • 833.24K Points
Coach

Q. How is a while loop different from a for loop in R?

  • (A) while loop is used for fixed iterations, for loop for variable iterations
  • (B) for loop is used for fixed iterations, while loop for variable iterations
  • (C) Both while and for loops are used for fixed iterations
  • (D) Both while and for loops are used for variable iterations