Control Structures In R Programming

Name: _____________________

Date: _____________________

Instructions: Answer all questions. Write your answers clearly in the space provided.

Question 1:

The only environment without a parent is the . . . . . . . . environment.

A. full
B. half
C. null
D. empty
Answer: _________
Question 2:

The . . . . . . . . function is a kind of "constructor function" that can be used to construct other functions.

A. make.pow()
B. make.power()
C. keep.power()
D. keep.pow()
Answer: _________
Question 3:

Which function in R language is used to find out whether the means of 2 groups are equal to each other or not?

A. f.tests ()
B. l.tests ()
C. t.tests ()
D. not exist
Answer: _________
Question 4:

What will be the output of the following R code? > f <- function() {
+ ## This is an empty function
+ }
> class(f)

A. "function"
B. "class"
C. "procedure"
D. "system"
Answer: _________
Question 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
E. Dynamic scoping turns out to be particularly useful for simplifying statistical computations
F. Lexical scoping turns out to be particularly useful for simplifying statistical computations
G. The scoping rules of a language determine how values are assigned to free variables
H. An environment is a collection of (symbol, value) pairs, i.e. x is a symbol and 3.14 might be its value
I. The primary task of debugging any R code is correctly diagnosing what the problem is
J. R provides only two tools to help you with debugging your code
K. print statement can be used for debugging purpose
L. The traceback() function must be called immediately after an error occurs
M. Functions in R are "second class objects"
N. The writing of a function allows a developer to create an interface to the code, that is explicitly specified with a set of parameters
O. Functions provides an abstraction of the code to potential users
P. Writing functions is a core activity of an R programmer
Q. The sapply() function behaves similarly to lapply()
R. With multiple factors and many levels, creating an interaction can result in many levels that are empty
S. apply() can be thought of as a combination of split() and sapply() for vectors only
T. You can use tsplit() to evaluate a function single time each with a same argument
U. for will execute a loop a fixed number of times
V. break will execute a loop while a condition is true
W. if and else tests a condition and acting on it
X. break is used to break the execution of a loop
Y. A formal argument can be a symbol, a statement of the form 'symbol = expression', or the special formal argument
Z. The first component of the function declaration is the keyword function
[. The value returned by the call to function is not a function
\. Functions are also often written when code must be shared with others or the public
]. The order of the packages on the search list does not matter
^. R has separate namespaces for functions and non-functions
_. Users can configure which packages get loaded on startup so if you are writing a function
`. The search list can be found by using the search() function
a. Statements cannot be grouped together using braces '{' and '}'
b. Computation in R consists of sequentially evaluating statements
c. Single statements are evaluated when a new line is typed at the end of the syntactically complete statement
d. next is used to skip an iteration of a loop
Answer: _________
Question 6:

. . . . . . . . is used to skip an iteration of a loop.

A. next
B. skip
C. group
D. cancel
Answer: _________
Question 7:

What will be the output of the following R code? > f <- function() {
+ ## This is an empty function
+ }
> f()

A. 0
B. No result
C. NULL
D. 1
Answer: _________
Question 8:

Which function calculates the count of each category of a categorical variable?

A. Table
B. Intact
C. Tables
D. Retabs
Answer: _________
Question 9:

. . . . . . . . applies a function over the margins of an array.

A. apply()
B. lapply()
C. tapply()
D. mapply()
Answer: _________
Question 10:

The syntax of the for loop is?

A. for ( $name in vector ) statement1
B. for loop( name in vector ) statement1
C. for ( name in vector ) statement1
D. forif loop( name in vector ) statement1
Answer: _________
Question 11:

What will be the output of the following R code? > printmessage2 <- function(x) {
+ if(is.na(x))
+ print("x is a missing value!")
+ else if(x > 0)
+ print("x is greater than zero")
+ else
+ print("x is less than or equal to zero")
+ invisible(x)
+ }
> printmessage2(NA)

A. "x is a missing value!"
B. "x is greater than zero"
C. "x is less than or equal to zero"
D. Error
Answer: _________
Question 12:

. . . . . . . . require you to pass a function whose argument is a vector of parameters.

A. optimize()
B. optimise()
C. opt()
D. opm()
Answer: _________
Question 13:

Which of the following is valid syntax for if else statement in R?

A. if(<condition>) { ## do something } else { ## do something else }
B. if(<condition>) { ## do something } elseif { ## do something else }
C. if(<condition>) { ## do something } else if { ## do something else }
D. if(<condition>) { ##& do something } else { ##@ do something else }
Answer: _________
Question 14:

What will be the class of the vector if you concatenate a number and NA?

A. Number
B. Character
C. Integer
D. No class
Answer: _________
Question 15:

What will be the output of the following R code snippet? > f <- function(a, b) {
+ a^2
+ }
> f(2)

A. 4
B. 3
C. 2
D. 5
Answer: _________
Question 16:

. . . . . . . . function is preferred over sapply as vapply allows the programmer to specific the output type.

A. Lapply
B. Japply
C. Vapply
D. Zapply
Answer: _________
Question 17:

The line of code in R language should begin with a . . . . . . . .

A. Hash symbol
B. Alphabet
C. Number
D. Character
Answer: _________
Question 18:

. . . . . . . . returns TRUE then X can be termed as a matrix data object.

A. is."matrix(X")
B. is.matrix(X)
C. is.notamatrix(X )
D. is.matrix("X")
Answer: _________
Question 19:

. . . . . . . . package provides basic functionalities in R environment like arithmetic calculations, input/output.

A. R base
B. R boost
C. R serve
D. R comm
Answer: _________
Question 20:

What will be the output of the following R code? > x <- 3
> switch(x, 2+2, mean(1:10), rnorm(5))

A. 2.2903605 2.3271663 -0.7060073 1.3622045 -0.2892720
B. 5.5
C. NULL
D. Error
Answer: _________
Question 21:

What will be the output of the following R code? > x <- 1:4
> lapply(x, runif)

A. [[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
B. [[1]] [1] 1.02778712 [[2]] [1] 2.5273108 0.8803191 [[3]] [1] 3.37306337 0.04795913 0.13862825 [[4]] [1] 0.3214921 0.1548316 0.1322282 0.2213059
C. [[1]] [1] 1.02778712 [[2]] [1] 0.5273108 0.8803191 [[3]] [1] 0.37306337 0.04795913 0.13862825 [[4]] [1] 3.3214921 2.1548316 1.1322282 0.2213059
D. Error
Answer: _________
Question 22:

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
Answer: _________
Question 23:

. . . . . . . . function gives an error message if the desired package cannot be loaded.

A. Dplyr
B. Require
C. Library
D. Sample
Answer: _________
Question 24:

What will be the output of the following R code? > x <- list(a = 1:5, b = rnorm(10))
> lapply(x, mean)

A. $a [1] 3 $b [1] 0.1322028
B. $a [1] 4 $b [1] 0.1322028
C. $a [1] 5 $b [1] 0.1322028
D. $a [2] 5 $b [1] 3
Answer: _________
Question 25:

Which of the following R code syntax is syntactically valid?

A. if ( statement1 ) { statement2 } else if ( statement3 ) { statement4 } else if ( statement5 ) { statement6 } else statement8
B. if ( statement1 ) { statement2 } elseif ( statement3 ) { statement4 } elseif ( statement5 ) { statement6 } else statement8
C. if ( statement1 ) { statement2 } elseif ( statement3 ) { statement4 } else if ( statement5 ) { statement6 } else statement8
D. if ( statement1 ) { statement2 } else if ( statement5 ) { statement6 } else statement8
Answer: _________
Question 26:

. . . . . . . . function takes various parameters like formula, data, subset, labels, etc.

A. Pears
B. Pairs
C. Tears
D. Cars
Answer: _________
Question 27:

. . . . . . . . functions can be "built which contain all of the necessary data for evaluating the function.

A. Objective
B. reflective
C. Nested
D. Symmetry
Answer: _________
Question 28:

Which of the following R code can be used to avoid numeric problems such as taking the logarithm of a negative number?

A. if( any(x < 0) ) y <- log(1+x) else y <- log(x)
B. if( any(x <= 0) ) y <- log(1+x) else y <- log(x)
C. if( any(x >= 0) ) y <- log(1+x) else y <- log(x)
D. if( any(x >> 0) ) x >- log(1+x) else x <- log(x)
Answer: _________
Question 29:

debug() flags a function for . . . . . . . . mode in R mode.

A. debug
B. run
C. compile
D. recover
Answer: _________
Question 30:

You can check to see whether an R object is NULL with the . . . . . . . . function.

A. is.null()
B. is.nullobj()
C. null()
D. as.nullobj()
Answer: _________
Question 31:

What will be the output of the following R expression? > log(-2.3)

A. Warning in log(-2.3): NaNs produced
B. 1
C. Null
D. 0
Answer: _________
Question 32:

Point out the correct statement?

A. lapply() takes elements of the list and passes them as the first argument of the function you are applying
B. You can use lapply() to evaluate a function multiple times each with a different argument
C. Functions that you pass to lapply() may have other arguments
D. None of the mentioned
E. The only way to exit a repeat loop is to call break
F. Infinite loops should generally be avoided
G. Control structures like if, while, and for allow you to control the flow of an R program
H. All of the mentioned
I. POSIX represents a portable operating system interface, primarily for UNIX systems
J. There are different levels of indication that can be used, ranging from mere notification to fatal error
K. The default input format for POSIX dates consists of the month, followed by the year and day, separated by slashes or dashes
L. R don't have any way to indicate to you that something's not right
M. The next statement causes an exit from the innermost loop that is currently being executed
N. There are two statements that can be used to explicitly control looping
O. The break statement immediately causes control to return to the start of the loop
P. Computation in R consists of sequentially evaluating statements
Q. Statements, such as x<-1:10 or mean(y), can be separated by either a semicolon or a new line
R. Whenever the evaluator is presented with a syntactically complete statement that statement is evaluated and the value returned
S. Computation in R consists of sequentially evaluating statements
T. All of the mentioned
U. The traceback() function must be called immediately after an error occurs
V. The debugger calls the browser at the very low level of the function body
W. Every time you call the mod() function it will launch the interactive debugger
X. R provides only two tools to help you with debugging your code
Y. Vectorizing the function can be accomplished easily with the Vectorize() function
Z. There are different levels of indication that can be used, ranging from mere notification to fatal error
[. Vectorizing the function can be accomplished easily with the vector() function
\. Warnings are generated by the run() function
]. Writing functions is a core activity of an R programmer
^. Functions are often used to encapsulate a sequence of expressions that need to be executed numerous times
_. Functions are also often written when code must be shared with others or the public
`. All of the mentioned
a. Blocks are evaluated until a new line is entered after the closing brace
b. Single statements are evaluated when a new line is typed at the start of the syntactically complete statement
c. The if/else statement conditionally evaluates two statements
d. Break will execute a loop while a condition is true
e. split() takes elements of the list and passes them as the first argument of the function you are applying
f. You can use tsplit() to evaluate a function single time each with a same argument
g. Sequence of operations is sometimes referred to as "map-reduce"
h. apply() can be thought of as a combination of split() and sapply() for vectors only
i. In R, a function is an object which has the mode function
j. R interpreter is able to pass control to the function, along with arguments that may be necessary for the function to accomplish the actions that are desired
k. Functions are also often written when code must be shared with others or the public
l. All of the mentioned
m. R has a number of ways to indicate to you that something's not right
n. Executing any function in R may result in the condition
o. "condition" is a generic concept for indicating that something unexpected has occurred
p. All of the mentioned
q. An environment is a collection of (symbol, value) pairs, i.e. x is a symbol and 3.14 might be its value
r. If the value of a symbol is not found in the environment in which a function was defined, then the search is continued in the child environment
s. After the top-level environment, the search continues down the search list until we hit the parent environment
t. Dynamic scoping turns out to be particularly useful for simplifying statistical computations
u. The search list can be found by using the searchlist() function
v. The search list can be found by using the search() function
w. The global environment or the user's workspace is always the second element of the search list
x. R has separate namespaces for functions and non-functions
Answer: _________
Question 33:

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)

A. Error
B. Warning
C. Messages
D. x is greater than zero
Answer: _________
Question 34:

A . . . . . . . . in R programming language can also contain numeric and alphabets along with special characters like dot and underline.

A. Variable name
B. Number
C. Integer
D. Character
Answer: _________
Question 35:

What will be the output of the following R code? > nLL <- make.NegLogLik(normals, c(FALSE, 2))
> optimize(nLL, c(-1, 3))$minimum

A. 1.217775
B. 2.217775
C. 3
D. empty
Answer: _________
Question 36:

How do you create log linear models in R language?

A. loglm()
B. logmn()
C. logfn()
D. loghy()
Answer: _________
Question 37:

The . . . . . . . . function returns a list of all the formal arguments of a function.

A. formals()
B. funct()
C. formal()
D. fun()
Answer: _________
Question 38:

What will be the output of the following R code? > x <- list(a = 1:4, b = rnorm(10), c = rnorm(20, 1), d = rnorm(100, 5))
> sapply(x, mean)

A. a b c d 2.500000 -0.251483 1.481246 4.968715
B. a b c d 2.500000 -3.251483 2.481246 5.968715
C. a b c d 3.500000 0.251483 1.481246 4.968715
D. Error
Answer: _________
Question 39:

Which function is used to create a histogram for visualisation in R programming language?

A. Library
B. Hist
C. Data
D. Refer
Answer: _________
Question 40:

. . . . . . . . function is used to apply an expression for a given dataset.

A. This()
B. With()
C. Unwith()
D. That()
Answer: _________
Question 41:

. . . . . . . . function is used in applying a function each level of factors.

A. With()
B. By()
C. To()
D. Here()
Answer: _________
Question 42:

The recover() function will first print out the function call stack when an . . . . . . . . occurs.

A. Error
B. Warning
C. Messages
D. delete
Answer: _________
Question 43:

The cumulative frequency distribution of a categorical variable can be checked using the . . . . . . . . function in R language.

A. Sum
B. Cumsum
C. Lumpsum
D. Resum
Answer: _________
Question 44:

R uses . . . . . . . . scoping 6 0 or static scoping.

A. reflective
B. transitive
C. lexical
D. closure
Answer: _________
Question 45:

R has . . . . . . . . statements that provide explicit looping.

A. 2
B. 3
C. 4
D. 5
Answer: _________
Question 46:

Which of the following statement can be used to explicitly control looping?

A. if
B. while
C. break
D. for
Answer: _________
Question 47:

. . . . . . . . prints out the function call stack after an error occurs.

A. trace()
B. traceback()
C. back()
D. traback()
Answer: _________
Question 48:

. . . . . . . . allows you to insert debugging code into a function a specific places

A. debug()
B. trace()
C. browser()
D. traceback()
Answer: _________
Question 49:

What will be the output of log (-5.8) when executed on R console?

A. NAN
B. NA
C. Error
D. 0.213
Answer: _________
Question 50:

Which of the following R syntax is correct for while loop?

A. while ( statement1 ) statement2
B. while ( statement1 ) else statement2
C. while ( statement1 ) do statement2
D. while ( statement2 ) doelse statement2
Answer: _________
Question 51:

Which package can be integrated with dplyr for large fast tables?

A. Table
B. Data, dplyr
C. Data.table
D. Dplyr.table
Answer: _________
Question 52:

Which package in R supports the exploratory analysis of genomic data?

A. Adegenat
B. Adegenet
C. Adegnet
D. Adezenet
Answer: _________
Question 53:

. . . . . . . . loop over a list and evaluate a function on each element.

A. apply()
B. lapply()
C. sapply()
D. mapply()
Answer: _________
Question 54:

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)

A. Error
B. Warning
C. Messages
D. Null
Answer: _________
Question 55:

Which of the following R code will print "Neither"?

A. > y <- "meat" > switch(y, fruit = "banana", vegetable = "broccoli", "Neither")
B. > y <- "brocolli" > switch(y, fruit = "banana", vegetable = "broccoli", "Neither")
C. > y <- "banana" > switch(y, fruit = "banana", vegetable = "broccoli", "Neither")
D. > y >- "banana" > y(y, fruit = "banana", vegetable = "broccoli", "Neither")
Answer: _________
Question 56:

. . . . . . . . function generates "n" normal random numbers based on the mean and standard deviation arguments passed to the function.

A. rnorm
B. vnorm
C. knorm
D. lnorm
Answer: _________
Question 57:

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. $a [1] 1 2 $b [1] 1 2 3
B. $a [1] 1 2 3 $b [1] 1 2 3
C. $a [1] 1 2 3 $b [1] 1 2
D. Error
Answer: _________
Question 58:

. . . . . . . . is the easiest method for reshaping the data before analysis.

A. Transpose()
B. Structure()
C. Package
D. Function
Answer: _________
Question 59:

Which function helps you perform sorting in R language?

A. Order
B. Inorder
C. Simple
D. Library
Answer: _________
Question 60:

What will be the output of the following R code? > f <- function(num) {
+ for(i in seq_len(num)) {
+ cat("Hello, world!
")
+ }
+ }
> f(3)

A. Hello, world! Hello, world!
B. Hello, world! Hello, world! Hello, world!
C. Hello, world!
D. Hello, world! Hello, world! Hello, world! Hello, world!
Answer: _________
Question 61:

. . . . . . . . is used to apply a function over subsets of a vector.

A. apply()
B. lapply()
C. tapply()
D. mapply()
Answer: _________
Question 62:

Which of the variable in the following R code is variable? > f <- function(x, y) {
+ x^2 + y / z
+ }

A. x
B. y
C. z
D. yy
Answer: _________
Question 63:

What will be the output of the following R code? function(p) {
params[!fixed] <- p
mu <- params[1]
sigma <- params[2]
## Calculate the Normal density
a <- -0.5*length(data)*log(2*pi*sigma^2)
b <- -0.5*sum((data-mu)^2) / (sigma^2)
-(a + b)
}
> ls(environment(nLL))

A. "data" "fixed" "param"
B. "data" "variable" "params"
C. "data" "fixed" "params"
D. "data" "param"
Answer: _________
Question 64:

. . . . . . . . initiates an infinite loop right from the start.

A. never
B. repeat
C. break
D. set
Answer: _________
Question 65:

What will be the output of runif()?

A. Random number
B. Numbers
C. Character
D. Path generation
Answer: _________
Question 66:

What will be the output of the following R code snippet? > g <- function(x) {
+ a <- 3
+ x+a+y
+ ## 'y' is a free variable
+ }
> g(2)

A. 9
B. 42
C. 8
D. Error
Answer: _________
Question 67:

. . . . . . . . will produce a sequential vector c( (1,2,3,4,5,6,7,8,9)).

A. Seq(9)
B. Seq(10)
C. Seq(15)
D. Seq(12)
Answer: _________
Question 68:

What are the different types of sorting algorithms available in R language?

A. Bubble
B. Selection
C. Merge
D. All sorts
Answer: _________
Question 69:

In R, what is the purpose of the ifelse() function?

A. To create a loop that iterates a specified number of times
B. To check a single condition and execute different code based on the result
C. To switch between different conditions and values
D. To generate random numbers based on a condition
Answer: _________
Question 70:

How is the for loop different from the while loop in R?

A. for loop is used for fixed iterations, while loop for variable iterations
B. while loop is used for fixed iterations, for loop for variable iterations
C. Both for and while loops are used for fixed iterations
D. Both for and while loops are used for variable iterations
Answer: _________
Question 71:

What does the Sys.sleep(2) function do in R?

A. Pauses the execution of R for 2 seconds
B. Sets the system clock to 2 seconds
C. Sleeps the R process for 2 milliseconds
D. Delays the execution of a loop by 2 seconds
Answer: _________
Question 72:

In R, how do you create an infinite loop?

A. repeat { code_block }
B. while (TRUE) { code_block }
C. for (i in 1:Inf) { code_block }
D. forever { code_block }
Answer: _________
Question 73:

In R, how do you create a switch statement with a default case?

A. switch(case_expression, list("case1" = expr1, "case2" = expr2, "default" = default_expr))
B. switch(case_expression, "case1" = expr1, "case2" = expr2, default = default_expr)
C. switch(case_expression, case1 = expr1, case2 = expr2, default = default_expr)
D. switch(case_expression, "case1", "case2", default = default_expr)
Answer: _________
Question 74:

In R, what is the purpose of the next statement in a loop?

A. Skips the next condition in an if-else statement
B. Exits the loop immediately
C. Moves to the next iteration of the loop
D. Restarts the loop from the beginning
Answer: _________
Question 75:

What will be the output of the following R code snippet? > lm <- function(x) { x * x }
> lm

A. function(x) { x * x }
B. func(x) { x * x }
C. function(x) { x / x }
D. function { x $ x }
Answer: _________
Question 76:

Write the syntax to set the path of the current working directory in R environment?

A. Setwd("dipath")
B. Setwd(dir_path)
C. Setwd("dir_path")
D. Set("dir_path")
Answer: _________
Question 77:

Which of the following language supports lexical scoping?

A. Perl
B. Python
C. Common Lisp
D. All of the mentioned
Answer: _________
Question 78:

What will be the value of following R expression?

A. Warning in log(c(-1, 2)): NaNs produced
B. Error in log(c(-1, 2)): NaNs produced
C. Message
D. All of the mentioned
Answer: _________
Question 79:

What will be the output of the following R code? > x <- 3
> switch(6, 2+2, mean(1:10), rnorm(5))

A. 10
B. 1
C. NULL
D. 5
Answer: _________
Question 80:

Warnings are generated by the . . . . . . . . function.

A. warning()
B. error()
C. run()
D. message()
Answer: _________
Question 81:

What will be the output of the following R code snippet? > paste("a", "b", sep = ":")

A. "a+b"
B. "a=b"
C. "a:b"
D. a*b
Answer: _________
Question 82:

What will be the output of the following R code? > mean(x)
Error in mean(x) : object 'x' not found
> traceback()

A. 1: mean(x)
B. Null
C. 0
D. 2
Answer: _________
Question 83:

What will be the output of the following R code snippet? > paste("a", "b", se = ":")

A. "a+b"
B. "a=b"
C. "a b :"
D. none of the mentioned
Answer: _________
Question 84:

CRAN package ecosystem has more than . . . . . . . . packages.

A. 5000
B. 4000
C. 6000
D. 8000
Answer: _________
Question 85:

. . . . . . . . function will measure the probability of the binary response variable in R language.

A. Glm()
B. Glmi()
C. Gelmi()
D. Jlm()
Answer: _________
Question 86:

How missing values and impossible values are represented in R language?

A. NA
B. NAN
C. NA & NAN
D. Not Exist
Answer: _________
Question 87:

What will be the output of the following R code? > x <- list(a = 1:4, b = rnorm(10), c = rnorm(20, 1), d = rnorm(100, 5))
> lapply(x, mean)

A. $a [1] 2.5 $b [1] 1.248845 $c [1] 1.9935285 Loop Functions 90 $d [1] 5.051388
B. $a [1] 2.5 $b [1] 0.248845 $c [1] 0.9935285 Loop Functions 90 $d [1] 5.051388
C. $a [1] 3.5 $b [1] 0.248845 $c [1] 0.9935285 Loop Functions 90 $d [1] 5.051388
D. Error
Answer: _________
Question 88:

The . . . . . . . . function takes a vector or other objects and splits it into groups determined by a factor or list of factors.

A. apply()
B. lsplit()
C. split()
D. mapply()
Answer: _________
Question 89:

The . . . . . . . . function is used to plot negative likelihood.

A. plot()
B. graph()
C. graph.plot()
D. plot.graph()
Answer: _________
Question 90:

lappy functions takes . . . . . . . . arguments in R language.

A. two
B. three
C. four
D. five
Answer: _________
Question 91:

Which function is more verbose?

A. Lapply
B. Japply
C. Vapply
D. Zapply
Answer: _________
Question 92:

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
Answer: _________
Question 93:

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
Answer: _________
Question 94:

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
Answer: _________
Question 95:

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
Answer: _________
Question 96:

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
Answer: _________
Question 97:

What does the next statement do in R?

A. Jumps to the next iteration of the loop
B. Ends the loop immediately
C. Skips the next condition in an if-else statement
D. Moves to the next element in a vector
Answer: _________
Question 98:

In R, what is the purpose of the repeat loop?

A. To repeat a block of code until a certain condition is met
B. To repeat a block of code a specified number of times
C. To repeat a block of code indefinitely
D. To repeat a block of code based on a specific condition
Answer: _________
Question 99:

What is the result of the expression 5 %% 2 in R?

A. 1
B. 2
C. 2.5
D. 0.5
Answer: _________
Question 100:

In R, what is the role of the ifelse() function?

A. To check a single condition and execute different code based on the result
B. To iterate over elements of a vector and apply a condition
C. To generate random numbers based on a condition
D. To switch between different conditions and values
Answer: _________
Question 101:

R Commander is used to . . . . . . . . in R.

A. Export data
B. Import data
C. Use data
D. Work on data
Answer: _________
Question 102:

R has . . . . . . . . basic indexing operators.

A. two
B. three
C. four
D. five
Answer: _________
Question 103:

Which of the following code skips the first 20 iterations?

A. for(i in 1:100) { if(i <= 20) { next } }
B. for(i in 1:100) { if(i <= 19) { next } }
C. for(i in 1:100) { if(i <= 21) { next } }
D. for(i in 1:10) { if(i <= 24) { next } }
Answer: _________
Question 104:

If the function in a console is.matrix(X) returns true then X can be considered as a . . . . . . . .

A. Matrix object
B. Matrix data object
C. Matrix vector
D. Vector
Answer: _________
Question 105:

How is a Data object represented internally in R language?

A. unclass (as.time ("2018-12-28"))
B. unclass (as.dat ("2018-12-28"))
C. unclass (as.D (2018-12-28))
D. unclass (as.Date ("2018-12-28"))
Answer: _________
Question 106:

. . . . . . . . function can be used to add datasets in R provided with the columns in the datasets should be the same.

A. rbind()
B. bbind()
C. jbind()
D. hbind()
Answer: _________
Question 107:

If the programmers want the output to be a data frame or a vector, then . . . . . . . . function is used.

A. Lapply
B. Sapply
C. Vapply
D. Zapply
Answer: _________
Question 108:

Which of the following should be preferred for evaluation from list of alternatives?

A. subsett
B. eval
C. switch
D. set
Answer: _________
Question 109:

What will be the class of the vector if you concatenate a number and a character?

A. Number
B. Character
C. Integer
D. No class
Answer: _________
Question 110:

Which of the following R code snippet stops loop after 20 iterations?

A. for(i in 1:100) { print(i) if(i > 20) { break } }
B. for(i in 1:100) { print(i) if(i > 19) { break } }
C. for(i in 1:100) { print(i) if(i < 20) { break } }
D. for(i in 2:100) { print("i") if(i > 150) { break } }
Answer: _________
Question 111:

. . . . . . . . package is used to speed up data frame management code.

A. Data.table
B. Dplyr
C. Table
D. Data.dplyr
Answer: _________
Question 112:

Which of the following is multivariate version of lapply?

A. apply()
B. lapply()
C. sapply()
D. mapply()
Answer: _________
Question 113:

Functions are defined using the . . . . . . . . directive and are stored as R objects.

A. function()
B. funct()
C. functions()
D. fun()
Answer: _________
Question 114:

MapReduce jobs submitted from either Oozie, Pig or Hive can be used to encode, improve and sample the data sets from . . . . . . . . into R.

A. HDLS
B. HDFS
C. HDLSV
D. HSSLV
Answer: _________
Question 115:

What will be the output of the following R code? > y <- "fruit"
> switch(y, fruit = "banana", vegetable = "broccoli", "Neither")

A. "banana"
B. "Neither"
C. "broccoli"
D. Error
Answer: _________
Question 116:

Which of the following R code generate a sequence of integers from 1 to 10?

A. > for(i in 1:9) { + print(i) + } [1]
B. > for(i in 0:9) { + print(i) + } [1]
C. > for(i in 1:10) { + print(i) + } [1]
D. > for(i in 2:50) { + print("i") + } [1]
Answer: _________
Question 117:

. . . . . . . . function is usually used inside another function and throws a warning whenever a particular package is not found.

A. Dplyr
B. Require
C. Coin
D. Sample
Answer: _________
Question 118:

How is a do-while loop implemented in R?

A. do { code_block } while (condition)
B. while (condition) { code_block }
C. do { code_block } until (condition)
D. while (condition) do { code_block }
Answer: _________
Question 119:

In R, what does the if (condition) { code_block } else { code_block } statement do?

A. Executes code_block if the condition is true, otherwise executes the else block
B. Executes code_block if the condition is false, otherwise executes the else block
C. Executes code_block if the condition is true, otherwise does nothing
D. Executes code_block if the condition is false, otherwise does nothing
Answer: _________
Question 120:

How is the repeat loop terminated in R?

A. Using the break statement
B. Using the stop statement
C. Using the terminate statement
D. Using the end statement
Answer: _________
Question 121:

What is the purpose of the which() function in R?

A. To determine the length of an object
B. To identify the positions of elements satisfying a condition
C. To create a loop based on certain conditions
D. To concatenate two vectors
Answer: _________
Question 122:

What is the output of the following R code: for (i in 1:5) { if (i %% 2 == 0) { print(i) } }

A. 2
B. 4
C. 2, 4
D. 1, 3, 5
Answer: _________
Question 123:

In R, what is the purpose of the repeat loop combined with break?

A. To create an infinite loop
B. To repeat a block of code until a certain condition is met
C. To skip the current iteration of the loop
D. To exit the loop immediately
Answer: _________
Question 124:

How is the switch() function different from if-else in R?

A. switch() is used for multiple conditions, if-else for two conditions
B. switch() can only handle numeric values, if-else can handle any type
C. if-else can only handle numeric values, switch() can handle any type
D. Both switch() and if-else are used interchangeably
Answer: _________
Question 125:

What is the role of the next statement in a loop in R?

A. To skip the next condition in an if-else statement
B. To exit the loop immediately
C. To move to the next iteration of the loop
D. To restart the loop from the beginning
Answer: _________
Question 126:

In R, what does the repeat loop combined with next do?

A. Repeats a block of code indefinitely and skips to the next iteration when a condition is met
B. Repeats a block of code a specified number of times and exits the loop immediately
C. Repeats a block of code a specified number of times and skips to the next iteration
D. Repeats a block of code indefinitely and exits the loop immediately
Answer: _________
Question 127:

A function, together with an environment, makes up what is called a . . . . . . . . closure.

A. formal
B. function
C. reflective
D. symmetry
Answer: _________
Question 128:

Body of lapply function is?

A. function (X, FUN, ...) { FUN <- match.fun(FUN) if (!is.vector(X) || is.object(X)) X <- as.list(X) .Internal(lapply(X, FUN)) }
B. function (X, FUN, ...) { FUN <- match.fun(FUN) if (!is.vector(X) | is.object(X)) X <- as.list(X) .Internal(lapply(X, FUN)) }
C. function (X, FUN, ...) { FUN <- match.fun(FUN) if (is.vector(X) || is.object(X)) X <- as.list(X) .Internal(lapply(X, FUN)) }
D. function (X, FUN, ...) { FUN <- match.fun(FUN) if (is.vector(X) || is.object(X)) }
Answer: _________
Question 129:

. . . . . . . . is used to break the execution of a loop.

A. next
B. skip
C. break
D. delete
Answer: _________
Question 130:

Write a function to extract the first name in the string "Mrs. Jake Luther"?

A. Substring
B. Substr
C. Substi
D. Return
Answer: _________
Question 131:

Which of the following R code will print the following result? [[1]]
[1] 2.263808
[[2]]
[1] 1.314165 9.815635
[[3]]
[1] 3.270137 5.069395 6.814425
[[4]]
[1] 0.9916910 1.1890256 0.5043966 9.2925392

A. > x <- 1:4 > lapply(x, runif, min = 0, max = 10)
B. > x <- 1:4 > lapply(x, runif, min = 0, max = 9)
C. > x <- 1:3 > lapply(x, runif, min = 0, max = 10)
D. > x <- 1:4 > lapply(x, runif, min = 0, max = 6)
Answer: _________
Question 132:

What will be the output of the following R code? > f <- function(num) {
+ hello <- "Hello, world!
"
+ for(i in seq_len(num)) {
+ cat(hello)
+ }
+ chars <- nchar(hello) * num
+ chars
+ }
> meaningoflife <- f(3)
> print(meaningoflife)

A. 32
B. 42
C. 52
D. 46
Answer: _________
Question 133:

. . . . . . . . function is same as lapply in R.

A. apply()
B. lapply()
C. sapply()
D. mapply()
Answer: _________
Question 134:

What would be the value of following R expression? log(-1)

A. Warning in log(-1): NaNs produced
B. 1
C. Null
D. 0
Answer: _________
Question 135:

The . . . . . . . . for R are the main feature that make it different from the original S language.

A. scoping rules
B. closure rules
C. environment rules
D. closure & environment rules
Answer: _________
Question 136:

What will be the output of the following R code? > f <- function(elt) {
+ elt[, 1]
+ }
> lapply(x, f)

A. $a [1] 1 2 $b [1] 1 2 3
B. $a [1] 1 2 3 $b [1] 1 2 3
C. $a [1] 1 2 3 $b [1] 1 2
D. Error
Answer: _________
Question 137:

Which function basically finds the intersection between two different sets of data?

A. Converge
B. Merge
C. Delegate
D. Swap
Answer: _________
Question 138:

. . . . . . . . can contain heterogeneous inputs.

A. Matrix
B. Data Frames
C. Matrix and Data Frames
D. Does not exists
Answer: _________
Question 139:

. . . . . . . . is one type of the simplest machine learning classification algorithms that is a subset of supervised learning based on lazy learning.

A. K-Nearest Neighbour
B. Naive Bayes
C. Travelling Salesman
D. N-Queen
Answer: _________
Question 140:

hat will be the output of the following R code? > centre <- function(x, type) {
+ switch(type,
+ mean = mean(x),
+ median = median(x),
+ trimmed = mean(x, trim = .1))
+ }
> x <- rcauchy(10)
> centre(x, "mean")

A. 0.8760325
B. 0.5360891
C. 0.6086504
D. gives mean with values depending on rcauchy values
Answer: _________
Question 141:

What are the data types in R on which binary operators can be applied?

A. Scalars
B. Matrices
C. Vectors
D. Scalars, Matrices and Vectors
Answer: _________
Question 142:

. . . . . . . . function is used for reading the .csv file in R language.

A. Write.csv()
B. Read.csv ()
C. Let.csv()
D. Table.csv()
Answer: _________
Question 143:

If a programmer wants the output to be a list then . . . . . . . . function is used.

A. Lapply
B. Sapply
C. Vapply
D. Zapply
Answer: _________
Question 144:

R code can be tested using . . . . . . . . package.

A. Dplyr
B. Hadley's testthat
C. SKLearn
D. KNN
Answer: _________
Question 145:

How many types of data structures does R language have?

A. 2
B. 3
C. 5
D. 8
Answer: _________
Question 146:

To get the current date, the . . . . . . . . function will return a Date object which can be converted to a different class if necessary.

A. Sys.Time
B. Sys.Date
C. Sys.DateTime
D. DateTime
Answer: _________
Question 147:

A matrix of scatterplots can be produced using . . . . . . . . function.

A. Pears
B. Pairs
C. Tears
D. Cars
Answer: _________
Question 148:

. . . . . . . . suspends the execution of a function wherever it is called and puts the function in debug mode.

A. debug()
B. trace()
C. recover()
D. browser()
Answer: _________
Question 149:

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.

A. Z <- (3, 2, 4)
B. Z <- (3, 6, 4)
C. Z <- (3, 4, 5)
D. Z <- (3, 4, 4)
Answer: _________
Question 150:

A programmer builds a . . . . . . . . to avoid repeating the same task or reduce complexity.

A. Function
B. Package
C. Code
D. Console
Answer: _________
Question 151:

Which of the following is valid body of split function?

A. function (x, f)
B. function (x, drop = FALSE, ...)
C. function (x, f, drop = FALSE, ...)
D. function (drop = FALSE, ...)
Answer: _________
Question 152:

Which of the following is apply function in R?

A. apply()
B. tapply()
C. fapply()
D. rapply()
Answer: _________
Question 153:

What will be the output of the following R code? > x <- 3
> switch(2, 2+2, mean(1:10), rnorm(5))

A. 5
B. 5.5
C. NULL
D. 58
Answer: _________
Question 154:

What will be the output of the following R code snippet? > f <- function(num = 1) {
+ hello <- "Hello, world!
"
+ for(i in seq_len(num)) {
+ cat(hello)
+ }
+ chars <- nchar(hello) * num
+ chars
+ }
> f()

A. Hello, world! [1] 14
B. Hello, world! [1] 15
C. Hello, world! [1] 16
D. Error
Answer: _________
Question 155:

. . . . . . . . function can be used to select the random sample of size 'n' from a huge dataset.

A. Simple()
B. Sample()
C. While()
D. Signal()
Answer: _________
Question 156:

. . . . . . . . package in R language provides various options for re-randomization and permutations based on statistical tests.

A. Coin
B. Vain
C. Join
D. Lain
Answer: _________
Question 157:

. . . . . . . . can be used for storing the data for long-term.

A. HDLS
B. HDFS
C. HDLSV
D. HSSLV
Answer: _________
Question 158:

What will be the output of the following R code? > g <- function(x) {
+ a <- 3
+ x+a+y
+ ## 'y' is a free variable
+ }
> y <- 3
> g(2)

A. 9
B. 42
C. 8
D. Error
Answer: _________
Question 159:

What is the memory limit in R for 64 bit system?

A. 8 TB
B. 9TB
C. 10TB
D. 16TB
Answer: _________
Question 160:

Which of the following code will print NULL?

A. > args(paste)
B. > arg(paste)
C. > args(pastebin)
D. > arg(bin)
Answer: _________
Question 161:

The current user defined objects like lists, vectors, etc. is referred to as . . . . . . . . in the R language.

A. Work names
B. Work space
C. Environment
D. Console
Answer: _________
Question 162:

If two vectors with different lengths perform some operation, the elements of the shorter vector will be used again to complete the operation. This is referred to as . . . . . . . .

A. Element Recycling
B. Recycling
C. Cycling
D. Element Cycling
Answer: _________
Question 163:

What is the memory limit in R for 32 bit system?

A. 8 TB
B. 9TB
C. 10TB
D. 3GB
Answer: _________
Question 164:

What will be the output of the following R code? > nLL <- make.NegLogLik(normals, c(1, FALSE))
> optimize(nLL, c(1e-6, 10))$minimum

A. 1.217775
B. 1.800596
C. 3.73424
D. empty
Answer: _________
Question 165:

. . . . . . . . variables are categorical variables which can hold either string or numeric values.

A. Factor
B. Simpler
C. Function
D. Package
Answer: _________
Question 166:

. . . . . . . . measures the probability of the binary response variable in R language.

A. Logical Regression
B. Multivariate Regression
C. Simpler Regression
D. Statistics
Answer: _________
Question 167:

. . . . . . . . is the best way for communicating the results of data analysis using the R language.

A. Single document
B. Files
C. Structures
D. Loadings
Answer: _________
Question 168:

Which function is difficult to implement?

A. Lapply
B. Japply
C. Vapply
D. Zapply
Answer: _________
Question 169:

. . . . . . . . allows you to modify the error behavior so that you can browse the function call stack

A. debug()
B. trace()
C. recover()
D. traceback()
Answer: _________
Question 170:

Which of the following is primary tool for debugging?

A. debug()
B. trace()
C. browser()
D. traceback()
Answer: _________
Question 171:

How will you check if an element is present in a vector?

A. Match()
B. Dismatch()
C. Mismatch()
D. Search()
Answer: _________
Question 172:

Which of the following R code will print "Hello, world!"?

A. > f <- function() { + cat("Hello, world! ") + } > f()
B. > f <- function() { + cat("Hello, World! ") + } < f()
C. > f <- function() { + cat("Hello world! ") + } >>= f()
D. > f <- function() { - cat("Hello world! ") + } <= f()
Answer: _________
Question 173:

What will be the output of the following R code snippet? > f <- function(a, b) {
+ print(a)
+ print(b)
+ }
> f(45)

A. 32
B. 42
C. 52
D. 45
Answer: _________
Question 174:

The syntax of the repeat loop is . . . . . . . .

A. rep statement
B. repeat statement
C. repeat else
D. repeat while
Answer: _________
Question 175:

In the base graphics system, which function is used to add elements to a plot?

A. Boxplot()
B. Text()
C. Boxplot() or Text()
D. Treat()
Answer: _________
Question 176:

Which of the following R code generate a uniform random number?

A. x <- runif(1, 0, 10) if(x > 3) { y <- 10 } else { y <- 0 }
B. x <- run(1, 0, 10) if(x > 3) { y <- 10 } else { y <- 0 }
C. x <- random(1, 0, 10) if(x > 3) { y <- 10 } else { y <- 0 }
D. x <- random(1, 0, 10) if(x > 1) { y <- 0 } else { x <- 0 }
Answer: _________
Question 177:

Which function is used to select variables and observations from a given dataset?

A. Subset()
B. Sample()
C. While()
D. Signal()
Answer: _________
Question 178:

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)

A. Error
B. Warning
C. Messages
D. 0
Answer: _________
Question 179:

. . . . . . . . is an indication that a fatal problem has occurred and execution of the function stops.

A. message
B. error
C. warning
D. message & warning
Answer: _________
Question 180:

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

A. even_numbers <- numeric(5) for (i in 1:5) { even_numbers[i] <- 2 * i }
B. even_numbers <- for (i in 1:5) { 2 * i }
C. even_numbers <- seq(2, 10, by = 2)
D. even_numbers <- c(2, 4, 6, 8, 10)
Answer: _________
Question 181:

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

A. primes <- numeric(5) num <- 2 while (length(primes) < 5) { if (all(num %% 2:(num-1) != 0)) { primes <- c(primes, num) } num <- num + 1 }
B. primes <- while (length(primes) < 5) { if (all(num %% 2:(num-1) != 0)) { c(primes, num) } num <- num + 1 }
C. primes <- c(2, 3, 5, 7, 11) while (length(primes) < 5) { primes <- c(primes, primes[length(primes)] + 2) }
D. primes <- numeric(5) for (i in seq(2, 11, by = 2)) { primes <- c(primes, i) }
Answer: _________
Question 182:

What is the output of the following R code: x <- 5
while (x > 0) { print(x)
x <- x - 2 }

A. 5, 3, 1
B. 5, 4, 3, 2, 1
C. 5, 2, 1
D. 5, 3, 2, 1
Answer: _________
Question 183:

How do you create a loop that prints the squares of numbers from 1 to 10 in R?

A. for (i in 1:10) { print(i^2) }
B. for (i = 1 i <= 10 i++) { print(i^2) }
C. while (i <= 10) { print(i^2) i <- i + 1 }
D. repeat { print(i^2) i <- i + 1 if (i > 10) break }
Answer: _________
Question 184:

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
Answer: _________
Question 185:

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 }
Answer: _________
Question 186:

What is the command used to store R objects in a file?

A. save (x, file="x.Rdata")
B. save (x, file=x.Rdata)
C. save (x, file="x.Rdata")
D. save (x, file="x.data")
Answer: _________

Answer Key

1: D
2: B
3: C
4: A
5: C, E, J, M, S, V, Y, ], a
6: A
7: C
8: A
9: A
10: C
11: A
12: C
13: A
14: A
15: A
16: C
17: A
18: B
19: A
20: A
21: A
22: A
23: C
24: A
25: A
26: B
27: A
28: B
29: B
30: A
31: A
32: D, H, I, N, T, U, Y, `, c, g, l, p, q, v
33: A
34: A
35: D
36: A
37: A
38: A
39: B
40: B
41: B
42: A
43: B
44: C
45: B
46: C
47: B
48: B
49: A
50: A
51: C
52: B
53: A
54: A
55: A
56: A
57: A
58: A
59: A
60: B
61: C
62: C
63: C
64: B
65: A
66: D
67: A
68: D
69: B
70: A
71: A
72: B
73: C
74: C
75: A
76: C
77: D
78: B
79: C
80: A
81: C
82: A
83: D
84: C
85: A
86: C
87: B
88: C
89: A
90: C
91: C
92: C
93: A
94: C
95: A
96: B
97: A
98: C
99: A
100: A
101: B
102: B
103: A
104: B
105: D
106: A
107: A
108: B
109: B
110: A
111: B
112: D
113: A
114: B
115: A
116: C
117: B
118: A
119: A
120: A
121: B
122: C
123: D
124: A
125: C
126: C
127: B
128: A
129: C
130: B
131: A
132: A
133: C
134: A
135: A
136: A
137: B
138: B
139: A
140: D
141: D
142: B
143: B
144: B
145: A
146: B
147: B
148: D
149: D
150: A
151: C
152: B
153: B
154: A
155: B
156: A
157: B
158: C
159: A
160: A
161: A
162: A
163: D
164: B
165: A
166: A
167: A
168: C
169: C
170: A
171: A
172: A
173: D
174: B
175: C
176: A
177: A
178: A
179: B
180: A
181: A
182: B
183: A
184: A
185: A
186: A