R Programming MCQ Questions And Answers - Loops
This section focuses on "Loops" in R Programming. These Multiple Choice Questions (MCQ) should be practiced to improve the R Programming skills required for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive examinations.
1. Which loop executes a sequence of statements multiple times and abbreviates the code that manages the loop variable?
A. for
B. while
C. do-while
D. repeat
View Answer
Ans : D
Explanation: repeat loop : Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable.
2. Which of the following true about for loop?
A. Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body.
B. it tests the condition at the end of the loop body.
C. Both A and B
D. None of the above
View Answer
Ans : B
Explanation: for loop : Like a while statement, except that it tests the condition at the end of the loop body.
3. Which statement simulates the behavior of R switch?
A. Next
B. Previous
C. break
D. goto
View Answer
Ans : A
Explanation: The next statement simulates the behavior of R switch.
4. In which statement terminates the loop statement and transfers execution to the statement immediately following the loop?
A. goto
B. switch
C. break
D. label
View Answer
Ans : C
Explanation: Break : Terminates the loop statement and transfers execution to the statement immediately following the loop.
5. Point out the wrong statement?
A. Multi-line expressions with curly braces are just not that easy to sort through when working on the command line
B. lappy() loops over a list, iterating over each element in that list
C. lapply() does not always returns a list
D. You cannot use lapply() to evaluate a function multiple times each with a different argument
View Answer
Ans : C
Explanation: lapply() always returns a list, regardless of the class of the input.
6. The mapply() function is a multivariate apply of sorts which applies a function in parallel over a set of arguments.
A. TRUE
B. FALSE
C. Can be true or false
D. Can not say
View Answer
Ans : A
Explanation: True, The mapply() function is a multivariate apply of sorts which applies a function in parallel over a set of arguments.
7. Which of the following is valid body of split function?
A. function (x, f)
B. function (x, f, drop = FALSE, …)
C. function (x, drop = FALSE, …)
D. function (drop = FALSE, …)
View Answer
Ans : B
Explanation: x is a vector (or list) or data frame
8. Which of the following character skip during execution?
v <- LETTERS[1:6]
for ( i in v) {
if (i == ""D"") {
next
}
print(i)
}
A. A
B. B
C. C
D. D
View Answer
Ans : D
Explanation: When the above code is compiled and executed, it produces the following result :
[1] ""A""
[1] ""B""
[1] ""C""
[1] ""E""
[1] ""F""
9. What will be output for the following code?
v <- LETTERS[1]
for ( i in v) {
print(v)
}
A. A
B. A B
C. A B C
D. A B C D
View Answer
Ans : A
Explanation: The output for the following code : [1] ""A""
10. What will be output for the following code?
v <- LETTERS[""A""]
for ( i in v) {
print(v)
}
A. A
B. NAN
C. NA
D. Error
View Answer
Ans : C
Explanation: The output for the following code : [1] NA
Discussion