wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

R variable Data Type and Flow Control Quiz

Total questions: 12

Worksheet time: 6mins

Name
Class
Date
1.

What is the correct way to assign a value to a variable in R?

a)

x <- 5

b)

x = 5

c)

5 -> x

d)

All of the above

2.

Which function is used to check the type of a variable in R?

a)

typeof()

b)

type()

c)

variable_type()

d)

None of the above

3.

Which of the following is true about variables in R?

a)

Variables cannot store multiple data types.

b)

Variables are case-sensitive.

c)

Variable names can start with a number.

d)

Variables name can have _

4.

What is the correct way to create a numeric vector in R?

a)

vector(1, 2, 3)

b)

[1, 2, 3]

c)

num(1, 2, 3)

d)

c(1, 2, 3)

5.

What will be the output of the following code?

a)

Error

b)

1, 2, 3

c)

2, 4, 6

d)

3, 4, 5

6.

Which of the following correctly creates a list in R?

a)

list("a", 1, TRUE)

b)

c("a", 1, TRUE)

c)

("a", 1, TRUE)

d)

None

7.

How do you access the third element of my_list as a List in R?

a)

my_list[3]

b)

my_list[[3]]

c)

my_list$3

d)

my_list(3)

8.

What function is used to create a matrix in R?

a)

create_matrix()

b)

array()

c)

mat()

d)

matrix()

9.

How do you access the element in the second row and third column of a matrix mat?

a)

mat[2, 2]

b)

mat[[2, 3]]

c)

mat[2][3]

d)

mat[2, 3]

10.

What will be the output of the following code?

a)

[1] 1 2 3

b)

[1] 7 8 9

c)

[1] 4 5 6

d)

None of the above

11.

What is the correct syntax for an if statement in R?

a)

if {condition} { ... }

b)

if condition { ... }

c)

if (condition) { ... }

d)

if [condition] { ... }

12.

What is the output of the following code?

a)

Error

b)

"Greater than 10"

c)

"10 or less"

d)

Nothing