wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Unit 2- R programming MCQs Quiz

Total questions: 148

Worksheet time: 1hrs 14mins

Name
Class
Date
1.

What is the difference between a scalar and a vector in R?

a)

A vector is a single-number variable, while a scalar is a variable that holds multiple numbers.

b)

A scalar and a vector are the same thing in R.

c)

A scalar is a single-number variable, whereas a vector is considered a different variable type that can hold multiple elements.

d)

R doesn't have a concept of scalars, only vectors.

2.

What are the R variable types called?

a)

Classes

b)

Modes

c)

Types

d)

Forms

3.

Which of the following is NOT a valid mode for an R vector?

a)

Integer

b)

Character

c)

Logical

d)

Object

4.

How are vectors stored in R, similar to arrays in C?

a)

Randomly

b)

Contiguously

c)

In a linked list

d)

In a hash table

5.

What happens when you try to insert or delete elements from a vector after it's been created?

a)

R automatically resizes the vector.

b)

It's not possible, as the size is determined at creation.

c)

You can, but it requires a special function.

d)

R throws an error.

6.

If x <- c(88, 5, 12, 13), what is the result of x <- c(x[1:3], 168, x[4])?

a)

c(88, 5, 12, 13, 168)

b)

c(168, 88, 5, 12, 13)

c)

c(88, 5, 12, 168, 13)

d)

c(88, 5, 168, 12, 13)

7.

What function is used to obtain the length of a vector?

a)

size()

b)

len()

c)

length()

d)

dim()

8.

What is the output of length(x) if x <- c()?

a)

NULL

b)

1

c)

0

d)

An error

9.

What does the expression 1:length(x) return if x <- c()?

a)

1 2 3

b)

1 0

c)

NULL

d)

An error

10.

In R, what are matrices and arrays considered to be?

a)

Data frames

b)

Lists

c)

Vectors

d)

Scalars

11.

Why do compiled languages require variable declarations?

a)

To save memory.

b)

To warn the interpreter/compiler of the variables' existence before use.

c)

To make the code run faster.

d)

To make the code more readable.

12.

Which of the following is a correct way to create a vector y with values 5 and 12?

a)

y[1] <- 5; y[2] <- 12

b)

y <- c(5,12)

c)

y <- vector(5,12)

d)

y(5,12)

13.

What is the behavior called when R automatically repeats the shorter vector to match the length of the longer one during an operation?

a)

Recycling

b)

Looping

c)

Resizing

d)

Extending

14.

What is the result of c(1,2,4) + c(6,0,9,20,22)?

a)

An error because the vectors have different lengths.

b)

c(7, 2, 13, 21, 24)

c)

c(7, 2, 13)

d)

c(7, 2, 13, 20, 22)

15.

What is the output of x+c(1,2) where x is the matrix [1 4; 2 5; 3 6]?

a)

[2 5; 4 7; 4 8]

b)

[2 5; 4 7; 4 8]

c)

[2 6; 4 6; 4 8]

d)

An error due to mismatched dimensions.

16.

What does the expression x + c(5,0,-1) evaluate to if x <- c(1,2,4)?

a)

c(6, 2, 3)

b)

c(1, 2, 4, 5, 0, -1)

c)

c(6, 2, 3, 5, 0, -1)

d)

An error

17.

What is the output of y[c(1,3)] if y <- c(1.2,3.9,0.4,0.12)?

a)

c(1.2, 0.4)

b)

c(1, 3)

c)

c(1.2, 3.9, 0.4)

d)

c(1.2, 0.12)

18.

What does a negative subscript like z[-1] do in vector indexing?

a)

It gives an error.

b)

It extracts the first element.

c)

It extracts all elements except for the first one.

d)

It extracts the last element.

19.

How can you pick up all elements of a vector z except for the last one?

a)

z[-length(z)]

b)

z[1:length(z)]

c)

z[length(z)]

d)

z[length(z)-1]

20.

What is the output of the colon operator 5:8?

a)

A vector from 5 to 8.

b)

The number 8.

c)

The numbers 5 and 8.

d)

An error.

21.

What function is a generalization of the colon operator : and generates a sequence in arithmetic progression?

a)

rep()

b)

c()

c)

seq()

d)

vector()

22.

What is the output of seq(from=12,to=30,by=3)?

a)

12 15 18 21 24 27 30 25

b)

12 30 3

c)

12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

d)

12, 15, 18, 21, 24, 27

23.

What function is used to repeat vector constants to create a new, longer vector?

a)

seq()

b)

c()

c)

rep()

d)

times()

24.

What does the expression rep(c(5,12,13),each=2) return?

a)

c(5, 12, 13, 5, 12, 13)

b)

c(5, 5, 12, 12, 13, 13)

c)

c(5, 12, 13, 2)

d)

c(10, 24, 26)

25.

What do the functions any() and all() report?

a)

The number of TRUE values in a vector.

b)

The number of FALSE values in a vector.

c)

Whether any or all of their arguments are TRUE.

d)

The sum of the TRUE values in a vector.

26.

Given x <- 1:10, what is the result of any(x > 8)?

a)

FALSE

b)

TRUE

c)

10

d)

2

27.

Given x <- 1:10, what is the result of all(x > 8)?

a)

TRUE

b)

FALSE

c)

10

d)

2

28.

When a function like round() is applied to a vector y, how does R process it?

a)

It applies the function to the entire vector at once.

b)

It applies the function to a random element of the vector.

c)

It applies the function individually to each element in the vector y.

d)

It throws an error because round() is not a vectorized function.

29.

What is the process of extracting a vector's elements that satisfy certain conditions called?

a)

Indexing

b)

Subsetting

c)

Filtering

d)

Slicing

30.

If z <- c(5,2,-3,8), what is the result of the expression z*z > 8?

a)

c(TRUE, FALSE, TRUE, TRUE)

b)

c(25, 4, 9, 64)

c)

c(TRUE, FALSE, FALSE, TRUE)

d)

c(5, -3, 8)

31.

What is the result of z[z*z > 8] if z <- c(5,2,-3,8)?

a)

c(5, 2, -3, 8)

b)

c(TRUE, FALSE, TRUE, TRUE)

c)

c(5, -3, 8)

d)

c(25, 9, 64)

32.

What is the key difference between using subset() and ordinary filtering for vectors?

a)

subset() is faster.

b)

subset() only works on data frames.

c)

subset() handles NA values differently.

d)

There is no difference.

33.

Given x <- c(6,1:3,NA,12), what is the output of x[x > 5]?

a)

c(6, 12)

b)

c(6, NA, 12)

c)

c(6, 1, 2, 3, 12)

d)

c(1, 2, 3)

34.

Given x <- c(6,1:3,NA,12), what is the output of subset(x,x > 5)?

a)

c(6, NA, 12)

b)

c(6, 12)

c)

c(6, 1, 2, 3, 12)

d)

NA

35.

What does the which() function return?

a)

The values of the elements that satisfy a condition.

b)

The indices of the elements that satisfy a condition.

c)

A vector of TRUE or FALSE values.

d)

The number of elements that satisfy a condition.

36.

If z <- c(5,2,-3,8), what is the output of which(z*z > 8)?

a)

c(5, -3, 8)

b)

c(1, 3, 4)

c)

c(TRUE, FALSE, TRUE, TRUE)

d)

c(25, 9, 64)

37.

What are the three arguments of the ifelse() function?

a)

b, u, v (Boolean vector, two vectors)

b)

x, y, z (vector, vector, vector)

c)

condition, value1, value2 (condition, value if true, value if false)

d)

test, yes, no (test, yes, no)

38.

Given x <- 1:10, what is the result of y <- ifelse(x %% 2 == 0,5,12)?

a)

c(5, 12, 5, 12, 5, 12, 5, 12, 5, 12)

b)

c(12, 5, 12, 5, 12, 5, 12, 5, 12, 5)

c)

c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

d)

c(5, 5, 5, 5, 5, 12, 12, 12, 12, 12)

39.

What is the output of x == y if x <- 1:3 and y <- c(1,3,4)?

a)

TRUE

b)

FALSE

c)

c(TRUE, FALSE, FALSE)

d)

An error

40.

How can you test if two vectors, x and y, are completely identical?

a)

x == y

b)

all(x == y)

c)

identical(x,y)

d)

Both b and c.

41.

How are the row and column subscripts for a matrix denoted in R?

a)

a[row, column]

b)

a(row, column)

c)

a[row][column]

d)

a[row-column]

42.

Given y <- matrix(c(1,2,3,4),nrow=2,ncol=2), what is the value of y[,2]?

a)

c(1, 2)

b)

c(1, 3)

c)

c(3, 4)

d)

An error

43.

What does the byrow=T argument in the matrix() function do?

a)

It fills the matrix by column instead of row.

b)

It fills the matrix by row instead of column.

c)

It transposes the matrix.

d)

It makes the matrix a data frame.

44.

How do you perform mathematical matrix multiplication in R?

a)

y * y

b)

y %*% y

c)

mult(y,y)

d)

y *%* y

45.

If y is the matrix [1 3; 2 4], what is the result of y + y?

a)

[1 6; 4 8]

b)

[2 6; 4 8]

c)

[2 4; 6 8]

d)

[2 3; 4 4]

46.

If z is a matrix, what does z[,2:3] extract?

a)

Rows 2 and 3.

b)

Columns 2 and 3.

c)

Elements at positions (2,3).

d)

An error.

47.

What is the value of y[2:3,2] if y is the matrix [11 12; 21 22; 31 32]?

a)

c(12, 22, 32)

b)

c(21, 31)

c)

c(22, 32)

d)

c(21, 22, 31, 32)

48.

What is the general form of the apply() function for matrices?

a)

apply(m, f, dimcode, fargs)

b)

apply(f, m, dimcode, fargs)

c)

apply(m, dimcode, f, fargs)

d)

apply(f, dimcode, m, fargs)

49.

In the apply() function for matrices, what does a dimcode of 2 signify?

a)

The function applies to rows.

b)

The function applies to columns.

c)

The function applies to both rows and columns.

d)

The function applies to a specific element.

50.

Given matrix z = [1 4; 2 5; 3 6], what is the result of apply(z, 2, mean)?

a)

c(2, 5)

b)

c(1, 2, 3)

c)

c(4, 5, 6)

d)

An error.

51.

Can you add or delete rows or columns directly to an existing matrix in R?

a)

Yes, using add() and delete() functions.

b)

Yes, but only for numeric matrices.

c)

No, matrices have fixed dimensions, but you can reassign the matrix with a new size.

d)

Yes, using list-like operations.

52.

What functions are used to add new rows or columns to a matrix by creating a new matrix?

a)

add.row() and add.col()

b)

rbind() and cbind()

c)

join.row() and join.col()

d)

insert() and delete()

53.

What does cbind(one,z) do if one is a vector and z is a matrix?

a)

It binds the rows of one and z.

b)

It binds one and z as new columns.

c)

It binds one and z as new rows.

d)

It gives an error because of mismatched types.

54.

What function is used to get the column names of a matrix?

a)

rownames()

b)

matrixnames()

c)

colnames()

d)

names()

55.

What is the fundamental characteristic of R's list structure?

a)

It can only hold objects of the same type.

b)

It is a single-number variable.

c)

It can combine objects of different types.

d)

It is a two-dimensional structure.

56.

A list is a type of what in R?

a)

Matrix

b)

Data frame

c)

Vector

d)

Scalar

57.

What are the names of list components called?

a)

Tags

b)

Keys

c)

Identifiers

d)

Names

58.

What are the three ways to access a component c of a list lst?

a)

lst$c, lst[["c"]], and lst[[i]]

b)

lst(c), lst[c], and lst{c}

c)

lst$c, lst["c"], and lst(i)

d)

lst[c], lst(c), and lst[i]

59.

What is the result of j[1:2] if j is a list with components name, salary, and union?

a)

A single vector with the first two values.

b)

A sublist containing the first two components.

c)

An error.

d)

A vector with the names "Joe" and 55000.

60.

How do you delete a list component?

a)

delete(list, component)

b)

list$component <- 0

c)

list$component <- NULL

d)

remove(list$component)

61.

What function is used to obtain the number of components in a list?

a)

size()

b)

count()

c)

length()

d)

dim()

62.

What function is used to get the tags (names) of list components?

a)

tags()

b)

names()

c)

labels()

d)

colnames()

63.

What does the unlist() function do to a list?

a)

It converts the list into a single vector.

b)

It removes the names of the elements.

c)

It converts the list to a data frame.

d)

It reverses the order of the elements.

64.

What is the class of the output of unlist() on a mixed-type list w <- list(a=5,b="xyz")?

a)

numeric

b)

list

c)

character

d)

mixed

65.

What function is used to remove the names of elements from a vector?

a)

names()

b)

unname()

c)

nonames()

d)

remove.names()

66.

Which function applies a specified function to each component of a list and returns a new list?

a)

sapply()

b)

tapply()

c)

lapply()

d)

apply()

67.

What is the primary difference between a matrix and a data frame?

a)

Matrices can have different data types in each column, while data frames cannot.

b)

Data frames can have different data types in each column, while matrices cannot.

c)

Matrices are a type of list, but data frames are not.

d)

Data frames are vectors, but matrices are not.

68.

What R functions are the heterogeneous analogs of vectors and matrices, respectively?

a)

lists and data frames

b)

vectors and matrices

c)

factors and tables

d)

scalars and arrays

69.

How is a data frame d with columns named kids and ages accessed like a list?

a)

d$kids and d$ages

b)

d(kids) and d(ages)

c)

d[1] and d[2]

d)

Both a and c.

70.

When a single column is extracted from a data frame, what is its default class?

a)

data.frame

b)

list

c)

The mode of the column (e.g., numeric or character).

d)

vector

71.

What argument to the indexing operator [] can be used to prevent a single-column extraction from a data frame from being converted to a vector?

a)

as.data.frame = TRUE

b)

keep.dims = TRUE

c)

drop = FALSE

d)

simplify = FALSE

72.

How can you extract a subframe of all students whose first exam score (Exam.1) was at least 3.8 from a data frame examsquiz?

a)

examsquiz[Exam.1 >= 3.8,]

b)

examsquiz[examsquiz$Exam.1 >= 3.8]

c)

examsquiz[examsquiz$Exam.1 >= 3.8,]

d)

subset(examsquiz, Exam.1 >= 3.8)

73.

When using rbind() to add a row to a data frame, what form should the added row typically be in?

a)

A vector.

b)

A matrix.

c)

Another data frame or a list.

d)

A scalar.

74.

What function can you use on a data frame if all the columns are of the same type?

a)

lapply()

b)

sapply()

c)

tapply()

d)

apply()

75.

What is the merge() function used for in R?

a)

To combine two vectors.

b)

To combine two matrices.

c)

To combine two data frames.

d)

To combine a list and a vector.

76.

What is the output of lapply(d, sort) on a data frame d?

a)

The sorted data frame d.

b)

A list where each element is a sorted column of d.

c)

A vector with all the sorted values.

d)

An error.

77.

What is the statistical concept that factors in R are based on?

a)

Ordinal variables.

b)

Interval variables.

c)

Nominal, or categorical, variables.

d)

Ratio variables.

78.

What extra information does a factor have in addition to being a vector?

a)

The length of the vector.

b)

The data type.

c)

A record of the distinct values, called levels.

d)

The mean and median of the values.

79.

What is the purpose of specifying levels when creating a factor?

a)

To change the order of the values.

b)

To add new values to the factor.

c)

To anticipate future new levels that might be assigned.

d)

To remove existing levels.

80.

What does the tapply(x, f, g) function do?

a)

It applies the function g to the vector x as a whole.

b)

It splits the vector x into groups based on the factor f and then applies the function g to each group.

c)

It applies the function g to the factor f.

d)

It creates a table from the vectors x and f.

81.

Given ages <- c(25,26,55,37,21,42) and affils <- c("R","D","D","R","U","D"), what is the output of tapply(ages,affils,mean)?

a)

A vector of all the ages.

b)

A list of the ages grouped by affiliation.

c)

A vector with the mean age for each affiliation group ("D", "R", "U").

d)

An error.

82.

What is the difference between tapply() and split()?

a)

split() applies a function to each group, while tapply() does not.

b)

tapply() applies a function to each group, while split() just forms the groups without applying a function.

c)

tapply() works only with vectors, while split() works with any data type.

d)

There is no difference.

83.

What is the output of split(1:7,g) if g <- c("M","F","F","I","M","M","F")?

a)

A vector 1 5 6 2 3 7 4.

b)

A list with components named F, I, and M, each containing the corresponding indices from the vector 1:7.

c)

A table showing the counts of each group.

d)

An error.

84.

In R, what is c() used for?

a)

Creating a character string.

b)

Combining values into a vector.

c)

Calculating the circumference of a circle.

d)

Clearing the console.

85.

Given the function first1 <- function(x) {for (i in 1:length(x)) {if (x[i] == 1) break} return(i)}, what does it return?

a)

The value 1.

b)

The first element of x that equals 1.

c)

The index of the first element in x that equals 1.

d)

The length of the vector x.

86.

What does the expression m + 10:13 demonstrate if m is a 2x2 matrix [1 2; 3 4]?

a)

Matrix addition.

b)

Matrix-scalar addition.

c)

Vector recycling in matrix operations.

d)

An error.

87.

What is the result of x / c(5,4,-1) if x <- c(1,2,4)?

a)

c(0.2, 0.5, -4.0)

b)

c(5, 8, -4)

c)

c(1, 2, 4)

d)

An error.

88.

What is the output of x %% c(5,4,-1) if x <- c(1,2,4)?

a)

c(1, 2, 0)

b)

c(0.2, 0.5, -4.0)

c)

c(1, 2, 4)

d)

c(0, 0, 0)

89.

How does y[v] work if y <- c(1.2,3.9,0.4,0.12) and v <- 3:4?

a)

It returns the third and fourth elements of y.

b)

It returns the third and fourth elements of v.

c)

It returns the third and fourth elements of y and v.

d)

It returns an error.

90.

What is the output of z[-1:-2] if z <- c(5,12,13)?

a)

c(12, 13)

b)

c(5, 12)

c)

13

d)

An error.

91.

What is the output of 5:1?

a)

c(1, 2, 3, 4, 5)

b)

c(5, 4, 3, 2, 1)

c)

c(5, 1)

d)

An error.

92.

What is the output of seq(from=1.1,to=2,length=10)?

a)

A sequence from 1.1 to 2.0 with a step of 0.1.

b)

c(1.1, 2.0, 10)

c)

A sequence from 1.1 to 2.0 with 10 elements.

d)

An error.

93.

What is the output of rep(1:3,2)?

a)

c(1, 1, 2, 2, 3, 3)

b)

c(1, 2, 3, 1, 2, 3)

c)

c(2, 4, 6)

d)

c(1, 2, 3)

94.

Given u <- c(5,2,8) and v <- c(1,3,9), what is the output of u > v?

a)

c(TRUE, TRUE, TRUE)

b)

c(FALSE, FALSE, FALSE)

c)

c(TRUE, FALSE, FALSE)

d)

An error.

95.

If w <- function(x) return(x+1), what is the result of w(u) if u <- c(5,2,8)?

a)

6

b)

c(6, 3, 9)

c)

c(5, 2, 8)

d)

An error.

96.

What is the output of round(y) if y <- c(1.2,3.9,0.4)?

a)

c(1.2, 3.9, 0.4)

b)

c(1, 4, 0)

c)

c(1, 3, 0)

d)

c(2, 4, 0)

97.

What is the result of ">"(2,5)?

a)

TRUE

b)

FALSE

c)

c(2, 5)

d)

>

98.

When a matrix is created, where does R start filling in the data by default?

a)

Row by row.

b)

Column by column.

c)

Diagonally.

d)

It's random.

99.

What is the value of 3*y if y is the matrix [1 3; 2 4]?

a)

[3 9; 6 12]

b)

[3 3; 3 3]

c)

[4 6; 5 7]

d)

[1 3; 2 4]

100.

What does y[c(1,3),] do if y is the matrix [1 4; 2 5; 3 6]?

a)

It extracts the first and third columns.

b)

It extracts the first and third rows.

c)

It extracts elements (1,1) and (3,3).

d)

It gives an error.

101.

If x is a matrix, what does the expression x[x[,2] >= 3,] do?

a)

It extracts all rows where the value in the second column is greater than or equal to 3.

b)

It extracts the rows where the second and third columns are greater than or equal to 3.

c)

It returns TRUE or FALSE for each row.

d)

It gives an error.

102.

What is the purpose of the *apply() family of functions?

a)

To create new vectors.

b)

To apply functions to matrix rows and columns.

c)

To perform logical operations on vectors.

d)

To manage data frames.

103.

Which of the following is NOT a feature of lapply()?

a)

Input can be a list, vector, or data frame.

b)

Output is always a list.

c)

It is used to apply a function to each element.

d)

It uses a factor to group data.

104.

Which apply() function is designed to apply a function to grouped subsets of a vector?

a)

lapply()

b)

sapply()

c)

tapply()

d)

apply()

105.

What is the result of x <- c(x,20) if x is the vector c(12, 5, 13, 16, 8)?

a)

c(12, 5, 13, 16, 8, 20)

b)

c(20, 12, 5, 13, 16, 8)

c)

c(12, 5, 13, 16, 20)

d)

An error.

106.

What is the output of x <- x[-2:-4] if x is c(12, 5, 13, 16, 8, 20)?

a)

c(12, 20)

b)

c(12, 8, 20)

c)

c(12, 16, 8, 20)

d)

c(5, 13, 16)

107.

What is the output of z[,"a"] if z is a matrix with column names c("a", "b")?

a)

The first column of the matrix.

b)

The first row of the matrix.

c)

An error.

d)

The character string "a".

108.

What is the difference between single and double brackets when accessing list elements?

a)

Single brackets return the element's value, while double brackets return a sublist.

b)

Single brackets return a sublist, while double brackets return the actual list component.

c)

Single brackets are for numeric indices, and double brackets are for names.

d)

There is no difference.

109.

How can you add a new component c with the value "sailing" to a list z?

a)

z <- c("sailing")

b)

z$c <- "sailing"

c)

z <- append(z,"sailing")

d)

z(c) <- "sailing"

110.

What is the output of names(j) if j is a list created with j <- list(name="Joe", salary=55000, union=T)?

a)

c("Joe", "55000", "TRUE")

b)

c("name", "salary", "union")

c)

c(1, 2, 3)

d)

NULL

111.

What is the class of the output of unlist(j) on a list j with numeric components?

a)

list

b)

character

c)

numeric

d)

integer

112.

What is the sapply() function used for?

a)

It simplifies the output of a function applied to a list to a vector, matrix, or array.

b)

It always returns a list.

c)

It groups data by a factor.

d)

It only works on numeric data.

113.

What does the recursive=T argument in the c() function do for lists?

a)

It prevents the list from being concatenated.

b)

It combines nested lists into a single, flat vector.

c)

It creates a new nested list.

d)

It gives an error.

114.

What are data frames considered to be?

a)

Atomic vectors.

b)

Recursive vectors.

c)

Matrices with a two-dimensional rows-and-columns structure.

d)

Heterogeneous analogs of lists.

115.

What is the output of examsquiz[2:5,2]?

a)

A data frame with rows 2 to 5 and column 2.

b)

A vector of the values in column 2, rows 2 to 5.

c)

The single element at row 2, column 2.

d)

An error.

116.

What is the output of examsquiz[2:5,2,drop=FALSE]?

a)

A vector of the values in column 2, rows 2 to 5.

b)

A data frame with one column containing the values from column 2, rows 2 to 5.

c)

An error because drop=FALSE is not a valid argument.

d)

The single element at row 2, column 2.

117.

When using cbind() to add a new column to a data frame, what must be true about the new column?

a)

It must have the same mode as the other columns.

b)

It must have the same length as the existing columns.

c)

It must be a vector.

d)

It must be a list.

118.

When merging two data frames, d1 and d2, using merge(d1, d2), which column is the merge based on by default?

a)

The first column.

b)

The last column.

c)

Common column names, like "kids" in the example.

d)

A specified merge key.

119.

What is the output of tapply(x,f,g) with multiple factors?

a)

A single vector.

b)

An error.

c)

The function g() is applied to subvectors of x corresponding to a combination of levels of the factors.

d)

The function is only applied to the first factor.

120.

If y <- c(1.2,3.9,0.4,0.12), what is the output of y[2:3]?

a)

c(1.2, 3.9)

b)

c(3.9, 0.4)

c)

c(0.4, 0.12)

d)

c(3.9, 0.12)

121.

What is the output of z[1:(length(z)-1)] if z <- c(5,12,13)?

a)

c(5, 12)

b)

c(5, 12, 13)

c)

c(12, 13)

d)

An error.

122.

What is the output of x <- rep(8,4)?

a)

A vector containing four 8s.

b)

A vector c(8, 8, 8, 8).

c)

A vector c(8, 4).

d)

An error.

123.

How is z*z > 8 evaluated internally by R?

a)

It first evaluates z*z, then performs the comparison.

b)

It recycles the number 8 to match the length of z*z.

c)

It treats > as a function ""(z*z, 8).

d)

All of the above.

124.

If y <- matrix(c(1,2,3,4),nrow=2), what is the output of y?

a)

[1 2; 3 4]

b)

[1 3; 2 4]

c)

[1 2; 4 3]

d)

[1 4; 2 3]

125.

If z <- list(a="abc",b=12), what is the output after z[[4]] <- 28 and z[5:7] <- c(FALSE,TRUE,TRUE)?

a)

An error because the list components must be contiguous.

b)

A list with components a, b, and then elements at indices 4, 5, 6, and 7.

c)

A list with a, b, and 28, FALSE, TRUE, TRUE.

d)

A list with the value 28 and then FALSE, TRUE, TRUE.

126.

What is the output of c(list("Joe", 55000, T),list(5))?

a)

A list of four components: "Joe", 55000, TRUE, and 5.

b)

An error.

c)

A list of two components, each a list.

d)

A vector of four elements.

127.

What is the class of ulj after ulj <- unlist(j) where j is a list containing name="Joe", salary=55000, union=T?

a)

list

b)

numeric

c)

character

d)

logical

128.

How can you remove the elements' names from a vector?

a)

names()

b)

remove.names()

c)

unname()

d)

un_names()

129.

What is the output of lapply(list(1:3,25:29),median)?

a)

c(2, 27)

b)

list(c(2), c(27))

c)

2 27

d)

An error.

130.

What is the purpose of stringsAsFactors=FALSE when creating a data frame?

a)

To save memory.

b)

To treat character columns as character strings instead of factors.

c)

To convert all strings to factors.

d)

To prevent strings from being used in the data frame.

131.

Given examsquiz, what does examsquiz[2:5,] do?

a)

It extracts a subdata frame consisting of rows 2 through 5.

b)

It extracts a subdata frame consisting of columns 2 through 5.

c)

It extracts elements from row 2 to 5.

d)

It returns an error.

132.

What does apply(examsquiz, 1, max) do?

a)

It returns a vector of the maximum value for each column.

b)

It returns a vector of the maximum value for each row.

c)

It returns the maximum value in the entire data frame.

d)

It gives an error because examsquiz has multiple column types.

133.

What is the output of length(xf) if x <- c(5,12,13,12) and xf <- factor(x)?

a)

3

b)

4

c)

5 12 13

d)

1

134.

What is the output of z*z > 8 if z <- c(5,2,-3,8)?

a)

c(25, 4, 9, 64)

b)

c(TRUE, FALSE, TRUE, TRUE)

c)

c(5, 2, -3, 8)

d)

An error

135.

What function is useful for filtering a vector and handling NA values differently from standard indexing?

a)

filter()

b)

subset()

c)

which()

d)

select()

136.

Which function is used to create a sequence in arithmetic progression, providing more control than the colon operator?

a)

rep()

b)

seq()

c)

c()

d)

vector()

137.

If you have a matrix z and you want to calculate the mean of each column, what dimcode would you use in apply()?

a)

1

b)

2

c)

0

d)

3

138.

What is the output of y <- ifelse(x > 6, 2*x, 3*x) if x <- c(5, 2, 9, 12)?

a)

c(10, 4, 18, 24)

b)

c(15, 6, 27, 36)

c)

c(15, 6, 18, 24)

d)

c(5, 2, 18, 24)

139.

How can you find out if a list a contains two components, without knowing what they are?

a)

length(a) == 2

b)

size(a) == 2

c)

a == 2

d)

names(a)

140.

What happens if you try to add or delete elements from an R vector?

a)

R throws an error.

b)

The vector automatically grows or shrinks.

c)

You cannot, as the size is fixed at creation, but you can create a new vector with the desired elements.

d)

The vector elements are set to NA.

141.

What is the output of rep(c(5,12,13),3)?

a)

c(5, 12, 13)

b)

c(5, 12, 13, 5, 12, 13, 5, 12, 13)

c)

c(15, 36, 39)

d)

c(5, 12, 13, 3)

142.

What is the primary difference between a list and a vector in R?

a)

A list can only hold one data type, while a vector can hold many.

b)

A vector is a list, but a list is not a vector.

c)

A list can combine objects of different types, while an atomic vector can only hold elements of the same mode.

d)

There is no difference.

143.

How does R handle the length of an empty vector x <- c()?

a)

length(x) returns an error.

b)

length(x) returns NULL.

c)

length(x) returns 0.

d)

length(x) returns 1.

144.

Which function simplifies the output of a list operation into a vector, matrix, or array?

a)

lapply()

b)

sapply()

c)

apply()

d)

tapply()

145.

What does the expression z[-length(z)] do if z is a vector?

a)

It removes the first element.

b)

It removes the last element.

c)

It returns the last element.

d)

It returns an error.

146.

What is the output of y[c(1,3)] if y <- c(1.2,3.9,0.4,0.12)?

a)

c(1.2, 0.4)

b)

c(1, 3)

c)

c(1.2, 3.9, 0.4)

d)

c(1.2, 0.12)

147.

What is the output of z*z > 8 if z <- c(5,2,-3,8)?

a)

c(TRUE, FALSE, TRUE, TRUE)

b)

c(25, 4, 9, 64)

c)

c(5, -3, 8)

d)

An error

148.

What is the primary use case for the tapply() function?

a)

Applying a function to each element of a vector.

b)

Applying a function to matrix rows and columns.

c)

Applying a function to grouped subsets of a vector based on a factor.

d)

Applying a function to a list.