Try to answer these 100+ R Programming MCQs and check your understanding of the R Programming subject.
Scroll down and let's begin!
Find the output of the following code on the R Interpreter.
months <- c{"JAN"."FEB"."MARCH"."APRIL"."MAY"."JUNE"."JULY")
output <- months[c(1.TRUE.4.TRUE.5)]
print(output)
A.
[1]'JAN' 'JAN' 'APRIL' 'JAN' 'MAY'
B.
[1]'JAN' 'FEB' 'APRIL' 'JAN' 'MAY'
C.
[1]' JAN' 'JAN' 'APRIL' 'MAY' ‘JUNE'
D.
[1]' JAN' 'FEB' 'MARCH' 'APRIL' 'MAY'
A. if
B. for
C. break
D. next
A. cbind()
B. rbind()
C. merge()
D. meit()
R uses the function. barplotii. to create bar charts. The basic syntax to create a bar chart In R is:
barplot(H. xlab. yiab. main. namesarg. col)
Which of the following options are correct?
A.
H is the title of the bar chart.
B.
main is a vector or matrix containing numeric values used in the bar chart.
C.
namesarg is a vector of names appearing under each bar.
D.
col is used to give colors to the bars in the graph.
Which of the given tasks are performed by the following code?
library("rjso")
result <- fromJSON(lile = '"data.json"]
print(result)
A.
I It loads the package required to read JSON files.
B.
It reads the file
C.
It prints the contents of the [son file.
D.
None of the above.
A. get the first n elements.
B. get elements from n+1 to the end.
C. get the nth element
D. get all elements but the nth element.
A. print(24L)
B. print(24)
C. print(12.5)
D. print(2+3i)
A. Xl-(iznll
B. Xllnil
C. ['1'] xfl'name
D. F1 x[i,j]
What will be the output of the following program on R interpreter?
v <- LETTERS[9.55:15.86]
for ( i in v)
{
if (i = "0")(
next
]
print(i)
}
A.
[1]'1'
[1] 'J'
[1]'k'
[1] 'L'
[1]M'
[1] 'N'
[1] '0'
B.
[1] 'l'
[11 'J'
[1] 'K'
[1]'’L'
[1]'M'
[1]W
C.
No output.
D.
[1] 'G'
A. Empty output
B. TESTOUTPUT
C. Compilation error
D. [1] TESTOUTPUT
What will be the output of the following program on R Interpreter?
v <- 3+16i
printiclass()
v <— 3"46
print[class[v])
v <~ 3l+16
printiclassMJ
v <- 316
print(class[v))
A.
O [t] 'complex'
[1119
[1] 'character'
[1] 'numeric‘
B.
[[1] 'complex'
[1] 'numeric'
[1] 'complex'
[1] 'numeric'
C.
Compilation error
D.
Runtime error
A. file
B. header
C. what
D. sep
E. quote
In R programming language. the arguments of a function can be partially matched using the following checks:
Check for a partial match.
Check for a positional match.
Check for exact match for a named argument
Which of the following Is the correct sequence of checks followed by the function to partially match the supplied arguments?
A.
ABC
B.
BCA
C.
CAB
D.
AcB
What will be the output of the following code on the R Interpreter?
print(seq(7,12. by = 0.68))
A.
[1] 7.68 8.36 9.04 9.7210.4011.0811.76
B.
[1] 7.00 7.68 8.36 9.04 9.7210.4011.0811.76
C.
[1] 7.00 7.68 8.36 9.04 9.7210.4011.08
D.
[1] 7.68 8.36 9.04 9.7210.4011.08
Following is a function definition in R programming language:
dummy.function <- function(a.b.c) [
result -=- a ‘+ b ' c
print(result)
]
Which of the following function calls will give the output: 41895?
A.
dummy.function(1345.200.31)
B.
dummy.function(200.1345.31)
C.
dummy.function(1345.31.200)
D.
dumnly.function(b=1345.a=200.c=31]
A. 13 4L
B. 4
C. 0L
D. 0
What will be the output of the following program on R interpreter?
OUTPUTMATRIX = matrix( c("1","2"."3"."4"."5"."6"."7"."8"."9"."10"."11","12"). nrow = 4, ncol = 3. byrow = FALSE)
print(OUTPUTMATRlX)
A.
[,1] [,2] [.3]
[1,] '1' '2' '3'
[2.] '4' '5' '6'
[3']'7' '8' '9'
[4.] '10' '11' '12'
B.
[1].[2][.3][,4]
[1'] 1' '2' '3' '4'
[2’] '5' '6' '7' '8'
[3'] '9' '10' 11'12'
C.
[111.211.311.41
[1,] '1' ' 4III7IIH10'
[2,] '2' '5ll118lll11'
[3’] '3' '6' '9' '12'
D.
[.1] [.2] [.3]
[1.] '1' ' 5' '9'
[2.] '2' '6' '10'
[3.] '3' '7' '11'
[4.] '4' '8' '12'
Following Is a function definition in R programming language:
foo.function <- function(a,b)
{
print{a)
print{b‘b)
}
Which of the following function calls will give an error?
A.
foo.function
B.
foo.functlon(9,5)
C.
foo.function[b=2,4)
D.
foo.functlon(9)
A. col
B. labels
C. radius
D. main
A. print(24L)
B. print(24)
C. printr12.5)
D. print(2+3i)
What will be the output of the following program on R interpreter?
temp <- c("Comp|ex","Simple")
cnt <- 10
repeat
[
print(temp)
cnt <— cnt-1
if(cnt < 6.5) {
break
1
}
A.
[1]"Complex""Simple"
[1] "Complex""Simple"
[1] "Complex""Simple"
[1] "Complex""Simple"
B.
Error in code execution
C.
System timeout error.
D.
[1]"Complex""Simple"
[1] "Complex""Simple"
A. operator creates the series of numbers in sequence for a vector.
B. 0%in% operator is used to multiply a matrix with its transpose.
C. %/% operator gives result of the division of first vector with second (quotient).
D. ^ operator gives the remainder of the division of first vector with the second.
A. foo <- c[O. 0.0.0)
B. foo <. c[10. 10. 10. 70)
C. foo <- c(-10. 10. 0. 90)
D. foo <- c[0. 10. 10. 90)
A. if
B. If...else
C. while
D. Switch
A. output <- read.csv('data.csv')
B. output <- readcsv(‘'data.csv')
C. output <- read('data.csv')
D. output <- readfile.csv('data.csv‘)
A. install.packages('xlsx‘)
B. any(grepl(‘x|sx',instalIed.packages()))
C. library('xlsx')
D. read.xlsx()
A. col
B. labels
C. radius
D. main
Following is a code snippet to be used to draw a boxplot in R:
boxplot(mpg "‘ Cyl, data = mtcars,
xiab = "Number of Cylinders",
ylab = Miles Per Gallon“,
main = "Mileage Data",
notch = TRUE,
varwldth = FALSE.
col = ched","Biue","Green"],
names = c("High","Medium","Low")
Which of the following options is NOT correct?
A.
it will draw a boxplot with 'Number of Cylinders' values on x axis and the Miles Per Gallon' data on y axis.
B.
it will give a title to the graph as Mileage Data
C.
it will draw the notch graphs
D.
It will draw a box with the width proportionate to the sample (data inputted) size.
E.
it will fill the color of the boxes as red, blue and green, respectively.
A. which(n = k)
B. match(n, k)
C. merge(n,k)
D. choose(n. K)
What wlll be the Output of the following program on R Interpreter?
v <- LETTERS[5:1]
{or (i in v)
{
print(i)
}
A.
[1] “E”
[1] "D"
[1] “C”
[1] "B"
[1] "A.”
B.
[1] “A”
[1] 'B-.
[I] "C'
C.
[1] “A"
[‘1 “B
[1] "C'
[1] D"
[1] "E'
D.
No output.
A. as.array
B. ls.data.frame
C. class(x)
D. whichmax(x)
Find the error in following code snippet
foodata <- data.frame(
empid = C(11:15),
empname = c("EMP2"."EMP3"."EMP4","EMP5"),
"" = c(100,200,300,400,500},
empjoindate = asDatetcf'2017—01-01", '2017~02~01", '2017-03-01‘, "2017-0401”,"2017~05-01‘)),
stringsAsFactors = FALSE
)
print(foo.data)
A.
One of the column names has a zero-length variable name.
B.
The column
C.
The data stored in a data frame is not of character type.
D.
The row names are not unique.
Following is a code snippet executed on R interpreter:
sales <- c(10,20.30.40.50)
months <- c{"JAN".“FEB"."MARCH"."APRIL"."MAY")
png(file = "months_sales.png")
barplot(sales,names.arg = months.xlab = "Month".ylab = "Sales",col = "Red",main = "Sales Chart“,border =
"Black")
What does this code do?
A.
It creates the vector data for the bar chart.
B.
It gives a name to the chart file.
C.
It plots the bar chart.
D.
It saves the chart as per the mentioned file name.
A. print(rootnode[[1]]11]]) will get the first element of the second node
B. printfrootnodeflimm) will get the first element of the first node.
C. xmlToDataFrarnefinputxml
D. xmlSize(rootnode) will find the number of child nodes under the root node.
Following is a function definition in R programming language:
foo.function <- function(a =1, b = 2. c = 3)
{result <- a ’ b+ c
print(result)
}
A.
foo.functlon()
B.
foo.functlon(8,6,4)
C.
foo.functlon(b=10,a=9)
D.
foo.function(1;1,1,1)
What will be the output of the following program on R Interpreter?
foo <- c(‘Testing‘.’while statement‘)
cnt <- 7
while [cnt<11.64)
[
printltoo)
cnt = count + 1
]
A.
No output.
B.
[1] 'Testlng’”while statement’
[1] "Testing‘'while statement'
[1] “Testing“while statement‘
[1] "Testing"‘while statement'
[1] "Testing”while statement‘
C.
[1] 'Testing"'while statement'
[1] "Testing-while statement‘
[1] "Testing‘"‘while statement‘
D.
Error in code executlon
What will be the output ofthe following program on R interpreter?
foo <- C("Testing","loop")
count <— 5
repeat {
print(foo)
count <- count +1
if(count > 8.34)[
break
}
]
A.
[1]"Testing""loop"
[1] "Testing""loop"
[1] "Testing""loop"
[1] "Testing""loop"
B.
[1] "Testing""loop"
[1] "Testing""loop"
[1] "Testing""loop"
C.
[1]"Testing""loop"
[1] "Testing"“loop"
D. No output.
What will be the output of the following R code?
car_colors <~ ci‘black',‘red','blue'.'blue'.'-.vltite'.‘metallic',‘red')
tactor_cars <~ Iactor(car_colors)
Print (factor_cars)
print(nlevels(factot_cats))
A.
Levels: black blue metallic red white
[1]5
B.
[1] black red blue blue White metallic red
Levels: black blue metallic red white
[1] 5
C.
[l] 5
D.
[1] black red blue blue white metallic red
Levels: black blue metallic red white
The middle-most value in a data series is called the median. The median() function is used. in R. to calculate this value. Which of the following are the valid parameters in the median() function?
A.
x, which is the input vector.
B.
trlm, which Is used to drop values from both ends of the sorted vector.
C.
na.rm, which is used to remove the missing values from the input vector.
R has four in-built functlons to generate a normal distributlon. Which of the following functions takes the probability value and gives a number. whose cumulative value matches the probability value?
A.
dnorm(x.mean. sd)
B.
pnorm(x.mean. sd)
C.
qnorm(p.mean. sd)
D.
rnorm(n. mean, sd)
in R language, in order to calculate the mean of a given set of values, the mean() function is used. Following is the basic syntax for the same:
mean(x, trim = O, na.rm = FALSE, ...)
Which of the following parameters is used to remove the missing values from the input vector?
A.
x
B.
trim
C.
na.rm
A. grep(pattern.x)
B. match(x,table)
C. merge(a,b)
D. choose(n, k)
R has four in-built functions to generate a normal distribution. Which of the following functions gives the height of the probability distribution at each point for a given mean and standard deviation?
A.
dnorm(x, mean, sd)
B.
pnorm(x, mean, sd)
C.
qnorm(p, mean, sd)
D.
rnorm(n, mean, sd)
A. 123L
B. 1 1 123
C. 999L
D. 2 999
You have an Excel workbook with the name "data.xlsx". it has 3 sheets. Which of the following options will load the Excel workbook and read the second sheet?
A.
data <- readodsxrdataxlsx', sheetlndex =1)
B.
data <~ read.xlsx(‘data.xlsx', sheetlndex = 2)
C.
data <- read.xlsxt(data.xlsx'. sheetlndex = 3)
D.
data <- read.xlsx('data.xlsx', sheetlndex = 0)
A. will load specified data sets.
B. will load add-on packages
C. will load the datasets written with save.
D. will start the HTML version of help.
A. formula, which is a symbol. presenting the relation between x and y.
B. data. which is the vector on which the formula will be applied.
C. object, which is the formula that is already created using the lm0 function.
D. newdata, which is the vector containing the new value for the predictor variable.
What will be the output of the following program on R interpreter?
custom_cub_function <- function()
i
for(i in 1:4)
{
i
cubeoutput <- i"3
print[cubeoutput)
}
A.
[1]1
[1]8
[1]27
[1]64
B.
[1]3
[1]6
[1]9
[1]12
C.
[1]0.3333333
[1] 0.6666667
[1]1
[1]1.333333
D.
No output.
What will be the output of the following program on R interpreter?
foo <- 'red'
switch(foo, fruit = "apple", vegetable = “chilli‘. "Exception')
A. red
B.
apple
C.
chilli
D.
Exception
What will be the output of the following program on R interpreter?
tempString <- "Hello.World!"
print (tempString)
tempString
A.
[1] "Hello,World!"
[1] "Hello,World!"
B.
[1] "Hello.World!"
C.
Compilation error
D.
Empty output