wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Introduction to R

Total questions: 18

Worksheet time: 9mins

Name
Class
Date
1.

How do you create a variable named x with the numeric value 5?

a)

x : 5

b)

x <- 5

c)

int x = 5

2.

The value of a string variable can be surrounded by single quotes.

a)

True

b)

False

3.

The following values: 10.5, 55 and 787, belongs to which data type?

a)
Integer
b)

numeric

c)
Boolean
4.

All elements of an atomic vector can be of different types.

a)
True
b)
False
c)
Depends on the vector
d)
Not sure
5.

You can construct a list using c( )

a)

True

b)

False

c)

Not sure

6.

Matrices and arrays are created with matrix( ) and array( ), or by using the assignment form of dim( )

a)

True

b)

False

c)

Not sure

7.

Consider the R code below, what is the type of vector a:

a <- c("r", 1)

a)

numeric

b)

character

c)

logical

d)

Integer

8.

Which of the type of data structures below is not homogeneous?

a)

atomic vector

b)

matrix

c)

array

d)

list

9.

A data frame is a list of equal-length vectors.

a)
True
b)
False
c)
Depends on the programming language
10.

Consider the R code below. How many factor levels are there?

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

a)

1

b)

2

c)

3

11.

How can you assign the same value to multiple variables in one line?

a)

var1, var2, var3 <- "orange"

b)

var1, var2, var3 = "orange"

c)

var1 <- var2 <- var3 <- "orange"

12.

How do you create a function in R?

a)

my_function <- function( )

b)

my_function <- function.

c)

my_function <- function[ ]

13.

How do you call a function in R?

a)

my_function( )

b)

my_function[ ]

c)

my_function;

d)

(my_function)

14.

What is the correct way to create a vector of strings?

a)

fruits <- c("banana", "apple", "orange")

b)

fruits <- v("banana", "apple", "orange")

c)

fruits <- list("banana", "apple", "orange")

d)

fruits <- listOf("banana", "apple", "orange")

15.

What is the correct way to create a list of strings?

a)

fruits <- c("banana", "apple", "orange")

b)

fruits <- v("banana", "apple", "orange")

c)

fruits <- list("banana", "apple", "orange")

d)

fruits <- listOf("banana", "apple", "orange")

16.

Which function can be used to create a data frame?

a)

dataframe( )

b)

data.frame( )

c)

df( )

d)

dframe( )

17.

What is the output of the following code fragment?

n = 10;

typeof(n);

class(n);

a)

[1] "double"

[1] "numeric"

b)

[1] "integer"

[1] "numeric"

c)

[1] "integer"

[1] "integer"

18.

Which of the following commands creates the vector
0, 0.2, 0.4, 0.6, 0.8, 1?

a)

x <- c(0, 0.2, 0.4, 0.6, 0.8, 1)

b)

seq(0, 1, by = 0.2)

c)

{0, 0.2, 0.4, 0.6, 0.8, 1}

d)

seq(0, 1, length=5)