wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Tutorial -1 (UNIT-I): Vectors in R

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

In R, which code correctly declares a numeric vector of three elements 2, 4, and 6?

a)

v := {2, 4, 6}

b)

v <- vector(2,4,6)

c)

v = [2, 4, 6]

d)

v <- c(2, 4, 6)

2.

Which statement best describes the difference between a scalar and a vector in R?

a)

A scalar stores lists, a vector stores matrices

b)

A scalar is character, a vector is numeric

c)

A scalar holds one value, a vector holds multiple

d)

A scalar is mutable, a vector is constant

3.

What is the output of length(c(3, 5, 7, 9)) in R?

a)

3

b)

5

c)

Error

d)

4

4.

Given x <- c(1,2,3) and y <- c(10,20,30), what is x + y?

a)

c(1,2,3,10,20,30)

b)

c(10,20,30)

c)

c(9,18,27)

d)

c(11,22,33)

5.

Which R code uses help to view documentation for the c function?

a)

help('c')

b)

help(c)

c)

All of the above

d)

?c

6.

If x <- c(TRUE, FALSE, TRUE) and y <- c(FALSE, TRUE, TRUE), what is x & y?

a)

c(TRUE, FALSE, TRUE)

b)

c(FALSE, TRUE, FALSE)

c)

c(TRUE, TRUE, TRUE)

d)

c(FALSE, FALSE, TRUE)

7.

Which result demonstrates R’s vector recycling when adding c(1,2) to c(10,20,30,40)?

a)

Error due to unequal lengths

b)

c(11,22,30,40)

c)

c(11,22,12,22)

d)

c(11,22,31,42)

8.

What does c() do in R?

a)

Casts a vector to numeric

b)

Combines values into a vector

c)

Counts elements in a vector

d)

Copies a vector to memory

9.

Which operation is valid element-wise on two equal-length numeric vectors in R?

a)

Addition with +

b)

Concatenation with ++

c)

Matrix multiplication with **

d)

Indexing with =>

10.

With x <- c(2,4,6) and a scalar s <- 3, what is x * s?

a)

c(6,12,18)

b)

c(2,4,6,3)

c)

c(5,7,9)

d)

Error: cannot multiply