Control Structures In R Programming — Part 2 MCQs with Explanations
Practice high-yield Programming & Software Development MCQs on Control Structures In R Programming — Part 2 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.
Questions
40
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
48 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
40
Verified Practice Questions
Interactive test mode with detailed academic worked solutions
Live Progress|0/40 answered
✓0 correct
✗0 wrong
0% score
🎉 Set complete! All 40 questions answered.
Question 1 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
R Commander is used to . . . . . . . . in R.
Correct Answer: Option B — Import data
Detailed Academic Explanation:
Import data is the correct answer to “R Commander is used to . . . . . . . . in R.”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
R has . . . . . . . . basic indexing operators.
Correct Answer: Option B — three
Detailed Academic Explanation:
three is the correct answer to “R has . . . . . . . . basic indexing operators.”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following code skips the first 20 iterations?
Correct Answer: Option A — for(i in 1:100) { if(i <= 20) { next } }
Detailed Academic Explanation:
for(i in 1:100) { if(i <= 20) { next } } is the correct answer to “Which of the following code skips the first 20 iterations”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
If the function in a console is.matrix(X) returns true then X can be considered as a . . . . . . . .
Correct Answer: Option B — Matrix data object
Detailed Academic Explanation:
Matrix data object is the correct answer to “If the function in a console is.matrix(X) returns true then X can be considered as a . . . . . . . .”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How is a Data object represented internally in R language?
Correct Answer: Option D — unclass (as.Date ("2018-12-28"))
Detailed Academic Explanation:
unclass (as.Date ("2018-12-28")) is the correct answer to “How is a Data object represented internally in R language”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
. . . . . . . . function can be used to add datasets in R provided with the columns in the datasets should be the same.
Correct Answer: Option A — rbind()
Detailed Academic Explanation:
rbind() is the correct answer to “. . . . . . . . function can be used to add datasets in R provided with the columns in the datasets should be the same.”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
If the programmers want the output to be a data frame or a vector, then . . . . . . . . function is used.
Correct Answer: Option A — Lapply
Detailed Academic Explanation:
Lapply is the correct answer to “If the programmers want the output to be a data frame or a vector, then . . . . . . . . function is used.”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
. . . . . . . . loop over a list and evaluate a function on each element.
Correct Answer: Option A — apply()
Detailed Academic Explanation:
apply() is the correct answer to “. . . . . . . . loop over a list and evaluate a function on each element.”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following R code? > printmessage <- function(x) { + if(x > 0) + print("x is greater than zero") + else + print("x is less than or equal to zero") + invisible(x) + } > printmessage(NA)
Correct Answer: Option A — Error
Detailed Academic Explanation:
Error is the correct answer to “What will be the output of the following R code? > printmessage <- function(x) { + if(x > 0) + print("x is greater than zero") + else + print("x is less than or equal to zero") + invisible(x) + } > printmessage(NA)”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the command used to store R objects in a file?
Correct Answer: Option A — save (x, file="x.Rdata")
Detailed Academic Explanation:
save (x, file="x.Rdata") is the correct answer to “What is the command used to store R objects in a file”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following R code will print "Neither"?
Correct Answer: Option A — > y <- "meat" > switch(y, fruit = "banana", vegetable = "broccoli", "Neither")
Detailed Academic Explanation:
> y <- "meat" > switch(y, fruit = "banana", vegetable = "broccoli", "Neither") is the correct answer to “Which of the following R code will print "Neither"”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 12 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
. . . . . . . . function generates "n" normal random numbers based on the mean and standard deviation arguments passed to the function.
Correct Answer: Option A — rnorm
Detailed Academic Explanation:
rnorm is the correct answer to “. . . . . . . . function generates "n" normal random numbers based on the mean and standard deviation arguments passed to the function.”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following R code? > x <- list(a = matrix(1:4, 2, 2), b = matrix(1:6, 3, 2)) > lapply(x, function(elt) { elt[,1] })
$a [1] 1 2 $b [1] 1 2 3 is the correct answer to “What will be the output of the following R code? > x <- list(a = matrix(1:4, 2, 2), b = matrix(1:6, 3, 2)) > lapply(x, function(elt) { elt[,1] })”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
. . . . . . . . is the easiest method for reshaping the data before analysis.
Correct Answer: Option A — Transpose()
Detailed Academic Explanation:
Transpose() is the correct answer to “. . . . . . . . is the easiest method for reshaping the data before analysis.”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
. . . . . . . . returns TRUE then X can be termed as a matrix data object.
Correct Answer: Option B — is.matrix(X)
Detailed Academic Explanation:
is.matrix(X) is the correct answer to “. . . . . . . . returns TRUE then X can be termed as a matrix data object.”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
. . . . . . . . package provides basic functionalities in R environment like arithmetic calculations, input/output.
Correct Answer: Option A — R base
Detailed Academic Explanation:
R base is the correct answer to “. . . . . . . . package provides basic functionalities in R environment like arithmetic calculations, input/output.”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following R code? > x <- 3 > switch(x, 2+2, mean(1:10), rnorm(5))
Correct Answer: Option A — 2.2903605 2.3271663 -0.7060073 1.3622045 -0.2892720
Detailed Academic Explanation:
2.2903605 2.3271663 -0.7060073 1.3622045 -0.2892720 is the correct answer to “What will be the output of the following R code? > x <- 3 > switch(x, 2+2, mean(1:10), rnorm(5))”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 18 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following R code? > x <- 1:4 > lapply(x, runif)
[[1]] [1] 0.02778712 [[2]] [1] 0.5273108 0.8803191 [[3]] [1] 0.37306337 0.04795913 0.13862825 [[4]] [1] 0.3214921 0.1548316 0.1322282 0.2213059 is the correct answer to “What will be the output of the following R code? > x <- 1:4 > lapply(x, runif)”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 19 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
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]) + }
Correct Answer: Option A — [1] "a" [1] "b" [1] "c" [1] "d"
Detailed Academic Explanation:
[1] "a" [1] "b" [1] "c" [1] "d" is the correct answer to “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]) + }”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
. . . . . . . . function gives an error message if the desired package cannot be loaded.
Correct Answer: Option C — Library
Detailed Academic Explanation:
Library is the correct answer to “. . . . . . . . function gives an error message if the desired package cannot be loaded.”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 21 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following R code? > x <- list(a = 1:5, b = rnorm(10)) > lapply(x, mean)
$a [1] 3 $b [1] 0.1322028 is the correct answer to “What will be the output of the following R code? > x <- list(a = 1:5, b = rnorm(10)) > lapply(x, mean)”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 22 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following R code syntax is syntactically valid?
Correct Answer: Option A — if ( statement1 ) { statement2 } else if ( statement3 ) { statement4 } else if ( statement5 ) { statement6 } else statement8
Detailed Academic Explanation:
if ( statement1 ) { statement2 } else if ( statement3 ) { statement4 } else if ( statement5 ) { statement6 } else statement8 is the correct answer to “Which of the following R code syntax is syntactically valid”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
. . . . . . . . function takes various parameters like formula, data, subset, labels, etc.
Correct Answer: Option B — Pairs
Detailed Academic Explanation:
Pairs is the correct answer to “. . . . . . . . function takes various parameters like formula, data, subset, labels, etc.”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
. . . . . . . . functions can be "built which contain all of the necessary data for evaluating the function.
Correct Answer: Option A — Objective
Detailed Academic Explanation:
Objective is the correct answer to “. . . . . . . . functions can be "built which contain all of the necessary data for evaluating the function.”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How many types of data structures does R language have?
Correct Answer: Option A — 2
Detailed Academic Explanation:
2 is the correct answer to “How many types of data structures does R language have”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
To get the current date, the . . . . . . . . function will return a Date object which can be converted to a different class if necessary.
Correct Answer: Option B — Sys.Date
Detailed Academic Explanation:
Sys.Date is the correct answer to “To get the current date, the . . . . . . . . function will return a Date object which can be converted to a different class if necessary.”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 27 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
A matrix of scatterplots can be produced using . . . . . . . . function.
Correct Answer: Option B — Pairs
Detailed Academic Explanation:
Pairs is the correct answer to “A matrix of scatterplots can be produced using . . . . . . . . function.”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 28 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
. . . . . . . . suspends the execution of a function wherever it is called and puts the function in debug mode.
Correct Answer: Option D — browser()
Detailed Academic Explanation:
browser() is the correct answer to “. . . . . . . . suspends the execution of a function wherever it is called and puts the function in debug mode.”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 29 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Two vectors M and N are defined as M <- c(3, 2, 4) and N <- c(1, 2). What will be the output of vector Z that is defined as Z <- M*N.
Correct Answer: Option D — Z <- (3, 4, 4)
Detailed Academic Explanation:
Z <- (3, 4, 4) is the correct answer to “Two vectors M and N are defined as M <- c(3, 2, 4) and N <- c(1, 2). What will be the output of vector Z that is defined as Z <- M*N.”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 30 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
A programmer builds a . . . . . . . . to avoid repeating the same task or reduce complexity.
Correct Answer: Option A — Function
Detailed Academic Explanation:
Function is the correct answer to “A programmer builds a . . . . . . . . to avoid repeating the same task or reduce complexity.”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is valid body of split function?
Correct Answer: Option C — function (x, f, drop = FALSE, ...)
Detailed Academic Explanation:
function (x, f, drop = FALSE, ...) is the correct answer to “Which of the following is valid body of split function”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 32 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is apply function in R?
Correct Answer: Option B — tapply()
Detailed Academic Explanation:
tapply() is the correct answer to “Which of the following is apply function in R”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following R code will print "Hello, world!"?
Correct Answer: Option A — > f <- function() { + cat("Hello, world!\n") + } > f()
Detailed Academic Explanation:
> f <- function() { + cat("Hello, world!\n") + } > f() is the correct answer to “Which of the following R code will print "Hello, world!"”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following R code snippet? > f <- function(a, b) { + print(a) + print(b) + } > f(45)
Correct Answer: Option D — 45
Detailed Academic Explanation:
45 is the correct answer to “What will be the output of the following R code snippet? > f <- function(a, b) { + print(a) + print(b) + } > f(45)”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 35 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The syntax of the repeat loop is . . . . . . . .
Correct Answer: Option B — repeat statement
Detailed Academic Explanation:
repeat statement is the correct answer to “The syntax of the repeat loop is . . . . . . . .”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 36 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In the base graphics system, which function is used to add elements to a plot?
Correct Answer: Option C — Boxplot() or Text()
Detailed Academic Explanation:
Boxplot() or Text() is the correct answer to “In the base graphics system, which function is used to add elements to a plot”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 37 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following R code generate a uniform random number?
Correct Answer: Option A — x <- runif(1, 0, 10) if(x > 3) { y <- 10 } else { y <- 0 }
Detailed Academic Explanation:
x <- runif(1, 0, 10) if(x > 3) { y <- 10 } else { y <- 0 } is the correct answer to “Which of the following R code generate a uniform random number”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is used to select variables and observations from a given dataset?
Correct Answer: Option A — Subset()
Detailed Academic Explanation:
Subset() is the correct answer to “Which function is used to select variables and observations from a given dataset”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 39 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following R code? > printmessage <- function(x) { + if(x > 0) + print("x is greater than zero") + else + print("x is less than or equal to zero") + invisible(x) + } > printmessage(1)
Correct Answer: Option A — Error
Detailed Academic Explanation:
Error is the correct answer to “What will be the output of the following R code? > printmessage <- function(x) { + if(x > 0) + print("x is greater than zero") + else + print("x is less than or equal to zero") + invisible(x) + } > printmessage(1)”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
. . . . . . . . is an indication that a fatal problem has occurred and execution of the function stops.
Correct Answer: Option B — error
Detailed Academic Explanation:
error is the correct answer to “. . . . . . . . is an indication that a fatal problem has occurred and execution of the function stops.”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡Examiner's Advisory for Programming & Software Development
In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.