WorksheetsR Quiz
Total questions: 26
Worksheet time: 14mins
How many types of R objects are present in R data type?
4
5
6
7
Which of this programming language is a dialect of R?
C
Python
CPP
S
In R the following are all atomic data types EXCEPT!
matrix
numeric
factor
list
What is the class of the object defined by x <- c(4, TRUE)?
character
numeric
logical
integer
Suppose I have a list defined as x <- list(2, "a", "b", TRUE). How can I fetch character vector "b" from the list?
x[[2]]
x[2]
x[[3]]
x[3]
x <- 1:4 , y <- 2:3, x+y = ?
3,5,3,4
3,5,5,7
Warning with some output
Error
To extract first two rows from data frame, we do
data(c[1,2],)
data[c(1,2)]
data(c[1,2])
data[c(1,2),]
cube <- function(x, n) {
x^3
}
What is the output of the above function? If called using
cube(4)
12
64
Warning: n is not used
Error
Consider the following function
f <- function(x) {
g <- function(y) {
y + z
}
z <- 4
x + g(x)
}
If I run in R:
z <- 10
f(3)
10
16
17
Warning: y not defined
What is the value of y?
x <- 5
y <- if(x < 3) {
NA
}
else {
10
}
10
NA
5
Error
Which of this initiates an infinite loop from the beginning?
while
for
set
repeat
If a command is not complete at the end of a line, R will give a different prompt, by default it is :
>
+
-
*
If you explicitly want an integer, you need to specify the _____ suffix.
R
L
D
I
What would be the result of following code ?
(x <- vector("numeric", length = 10))
10
0 0 0 0 0 0 0 0 0 0
"numeric"
None of the above
Output of the following code:
x <- 0:3
as.logical(x)
0 1 2 3
"0" "1" "2" "3"
FALSE TRUE TRUE TRUE TRUE
0 1 2
Output of sqrt(-16)
4
-4
NaN
NA
What would be the result of following code ?
x <- c("a", "b", "c")
as.numeric(x)
1 2 3
97 98 99
Warning
Error
Which of the below are INCORRECT example of R data type?
Complex
Integer
Logical
String
The __________ function returns a list of all the formal arguments of a function
formalArgs()
formalArg()
formals()
formal()
Which of these is not valid?
x <- y <- T
x = y = T
x <- y = T
x = y <- T
Output:
if(x = F) print("In if block") else print("In else block")
In if block
In else block
Error
FALSE
Output:
1:5 %/% 3
0 0 1 1 1
0.33 0.66 1.00 1.33 1.66
1 2 0 1 2
Error
Output:
c(NA & F, NA | T, NA & T, NA | F)
FALSE TRUE NA NA
NA TRUE NA FALSE
FALSE NA TRUE NA
NA NA TRUE FALSE
Output:
paste0 (c("red", "yellow"), "flower", sep = "-", collapse = "$")
"red-flower$yellow-flower"
"redflower-$yellowflower-"
"red$flower-yellow$flower"
"redflower$-yellowflower$"
Correct way to print
Hello
World
is?
print('Hello\n World')
cat('Hello\n World')
sprintf('Hello\n World')
paste('Hello\n World')
Output:
gl(6,1,9)
1 2 3 4 5 6 1 2 3
1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 ... (total 6 times)
6 6 6 6 6 6 6 6 6
1 2 3 4 5 6 1 2 3 4 5 6 ... (total 9 times)
