wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

R Quiz

Total questions: 26

Worksheet time: 14mins

Name
Class
Date
1.

How many types of R objects are present in R data type?

a)

4

b)

5

c)

6

d)

7

2.

Which of this programming language is a dialect of R?

a)

C

b)

Python

c)

CPP

d)

S

3.

In R the following are all atomic data types EXCEPT!

a)

matrix

b)

numeric

c)

factor

d)

list

4.

What is the class of the object defined by x <- c(4, TRUE)?

a)

character

b)

numeric

c)

logical

d)

integer

5.

Suppose I have a list defined as x <- list(2, "a", "b", TRUE). How can I fetch character vector "b" from the list?

a)

x[[2]]

b)

x[2]

c)

x[[3]]

d)

x[3]

6.

x <- 1:4 , y <- 2:3, x+y = ?

a)

3,5,3,4

b)

3,5,5,7

c)

Warning with some output

d)

Error

7.

To extract first two rows from data frame, we do

a)

data(c[1,2],)

b)

data[c(1,2)]

c)

data(c[1,2])

d)

data[c(1,2),]

8.

cube <- function(x, n) {

x^3

}

What is the output of the above function? If called using

cube(4)

a)

12

b)

64

c)

Warning: n is not used

d)

Error

9.

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)

a)

10

b)

16

c)

17

d)

Warning: y not defined

10.

What is the value of y?

x <- 5

y <- if(x < 3) {

NA

}

else {

10

}

a)

10

b)

NA

c)

5

d)

Error

11.

Which of this initiates an infinite loop from the beginning?

a)

while

b)

for

c)

set

d)

repeat

12.

If a command is not complete at the end of a line, R will give a different prompt, by default it is :

a)

>

b)

+

c)

-

d)

*

13.

If you explicitly want an integer, you need to specify the _____ suffix.

a)

R

b)

L

c)

D

d)

I

14.

What would be the result of following code ?

(x <- vector("numeric", length = 10))

a)

10

b)

0 0 0 0 0 0 0 0 0 0

c)

"numeric"

d)

None of the above

15.

Output of the following code:

x <- 0:3

as.logical(x)

a)

0 1 2 3

b)

"0" "1" "2" "3"

c)

FALSE TRUE TRUE TRUE TRUE

d)

0 1 2

16.

Output of sqrt(-16)

a)

4

b)

-4

c)

NaN

d)

NA

17.

What would be the result of following code ?

x <- c("a", "b", "c")

as.numeric(x)

a)

1 2 3

b)

97 98 99

c)

Warning

d)

Error

18.

Which of the below are INCORRECT example of R data type?

a)

Complex

b)

Integer

c)

Logical

d)

String

19.

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

a)

formalArgs()

b)

formalArg()

c)

formals()

d)

formal()

20.

Which of these is not valid?

a)

x <- y <- T

b)

x = y = T

c)

x <- y = T

d)

x = y <- T

21.

Output:

if(x = F) print("In if block") else print("In else block")

a)

In if block

b)

In else block

c)

Error

d)

FALSE

22.

Output:

1:5 %/% 3

a)

0 0 1 1 1

b)

0.33 0.66 1.00 1.33 1.66

c)

1 2 0 1 2

d)

Error

23.

Output:

c(NA & F, NA | T, NA & T, NA | F)

a)

FALSE TRUE NA NA

b)

NA TRUE NA FALSE

c)

FALSE NA TRUE NA

d)

NA NA TRUE FALSE

24.

Output:

paste0 (c("red", "yellow"), "flower", sep = "-", collapse = "$")

a)

"red-flower$yellow-flower"

b)

"redflower-$yellowflower-"

c)

"red$flower-yellow$flower"

d)

"redflower$-yellowflower$"

25.

Correct way to print

Hello

World

is?

a)

print('Hello\n World')

b)

cat('Hello\n World')

c)

sprintf('Hello\n World')

d)

paste('Hello\n World')

26.

Output:

gl(6,1,9)

a)

1 2 3 4 5 6 1 2 3

b)

1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 ... (total 6 times)

c)

6 6 6 6 6 6 6 6 6

d)

1 2 3 4 5 6 1 2 3 4 5 6 ... (total 9 times)