β˜‘ MCQ PRACTICE

R Programming Unit 2

Practice objective questions for quick revision and examination preparation. Try answering each question before revealing the answer.

πŸ“š R Programming
πŸ“– Unit 2
🎯 MCQs
MCQ Practice

R Programming β€” Unit 2

Practice the following objective questions. Click β€œShow Answer” whenever you want to check your answer.

01

Which of the following is NOT a control structure in R?

A if-else
B for
C while
D switch-case
Correct Answer switch-case
02

How do you define a function in R?

A function myFunc() { }
B def myFunc() { }
C myFunc <- function() { }
D create function myFunc() { }
Correct Answer myFunc <- function() { }
03

What will be the output of c(1,2,3) + c(4,5,6)?

A c(5,7,9)
B c(4,5,6,1,2,3)
C c(1,2,3,4,5,6)
D Error
Correct Answer c(5,7,9)
04

How do you check the length of a vector?

A size()
B length()
C dim()
D count()
Correct Answer length()
05

What will seq(1, 10, by=3) generate?

A c(1,2,3,4,5,6,7,8,9,10)
B c(1,4,7,10)
C c(1,5,10)
D c(1,2,5,7,10)
Correct Answer c(1,4,7,10)
06

What is the default mode of a vector created using c(1,2,3,4)?

A Character
B Integer
C Numeric
D Logical
Correct Answer Numeric
07

How do you remove an element from a vector?

A remove(vector, index)
B vector <- vector[-index]
C del(vector, index)
D vector.delete(index)
Correct Answer vector <- vector[-index]
08

What will rep(1, times=5) produce?

A c(1,1,1,1,1)
B c(1,5)
C c(5,5,5,5,5)
D Error
Correct Answer c(1,1,1,1,1)
09

How do you extract the 3rd element from a vector v?

A v{3}
B v(3)
C v[3]
D v[[3]]
Correct Answer v[3]
10

What will 1:5 * 2 return?

A c(1,2,3,4,5,2,4,6,8,10)
B c(2,4,6,8,10)
C c(1,2,3,4,5,2)
D Error
Correct Answer c(2,4,6,8,10)
11

What will length(c(TRUE, FALSE, TRUE)) return?

A 3
B 2
C 1
D TRUE
Correct Answer 3
12

How do you check if an object is a matrix?

A is.matrix()
B isMatrix()
C matrix.check()
D is.mat()
Correct Answer is.matrix()
13

How do you create a 3x3 matrix with values 1 to 9?

A matrix(1:9, nrow=3, ncol=3)
B matrix(1,9,3,3)
C mat(1:9, 3, 3)
D array(1:9, c(3,3))
Correct Answer matrix(1:9, nrow=3, ncol=3)
14

How do you create a list in R?

A list(a=1, b=2, c=3)
B c(a=1, b=2, c=3)
C array(a=1, b=2, c=3)
D vector(a=1, b=2, c=3)
Correct Answer list(a=1, b=2, c=3)
15

How do you extract an element from a list in R?

A listname[element]
B listname[[element]]
C listname{element}
D listname.element
Correct Answer listname[[element]]
16

What function is used to get the current date?

A Sys.time()
B Sys.Date()
C date()
D currentDate()
Correct Answer Sys.Date()
17

What will as.logical(0) return?

A TRUE
B FALSE
C 0
D Error
Correct Answer FALSE
18

Which loop is used to iterate over a sequence in R?

A for loop
B while loop
C repeat loop
D if loop
Correct Answer for loop
19

Which function is used to return a value from a function in R?

A return()
B output()
C result()
D value()
Correct Answer return()
20

Which function is used to assign a value to a global variable inside a function in R?

A global()
B assign()
C set()
D <<-
Correct Answer <<-
21

Which function is used to create a sequence of numbers in R?

A seq()
B sequence()
C range()
D generate()
Correct Answer seq()
Quick Revision

Fill in the Blanks

Complete the following R Programming questions.

01
What does nrow() return? __________________________
Answer Number of rows in a matrix
02
What does ncol() return? ____________________________
Answer Number of columns in a matrix
03
What is the output of Sys.time()? _______________________________
Answer Current date and time
04
________________ function is used to check the type of an object?
Answer class()
05
____________________ function is used to check if a variable is a function?
Answer is.function()
06
How do you extract an element from a matrix? ______________________
Answer matrix[row, column]
07
____________________ function is used to convert a matrix to a vector?
Answer as.vector()
08
What does is.numeric("5") return? ______________________________
Answer FALSE
09
____________________ is used to create an empty vector?
Answer vector()
← Back to All MCQs