wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

BSCS 4-3 - Midterm Exam (Jan. 6, 2024)

Total questions: 50

Worksheet time: 25mins

Name
Class
Date
1.

What best describes R in programming?

a)

A programming language for statistics and data analysis

b)

A web development language

c)

An operating system

d)

A gaming software

2.

Which of the following is the correct sequence for installing R and R Studio?

a)

Install R first, then R Studio

b)

Install R Studio first, then R

c)

Installation order doesn't matter

d)

Install both simultaneously

3.

What is the purpose of the 'Environment' tab in RStudio?

a)

To display all installed packages

b)

To manage files and folders

c)

To view objects, variables, and their values

d)

To write and execute code

4.

Which operator is used in R for exponentiation?

a)

**

b)

//

c)

%

d)

^

5.

What's the primary purpose of a function in R?

a)

Plotting graphs

b)

Storing datasets

c)

Reusing code and performing specific tasks

d)

Writing comments in code

6.

Which of the following R code will correctly compute and display output of 45?

a)

b)

c)

d)

7.

In a bakery dataset, the variable 'bread' represents the number of loaves sold, and 'price' is the cost per loaf. The following R code is used: (see the attached image)

What does the variable 'income' represent?

a)

Total loaves available

b)

Total expenses

c)

Average price per loaf sold

d)

Total revenue generated

8.

In a stock market dataset, 'opening_price' represents the stock's opening price, 'closing_price' denotes the closing price, and 'volume' signifies the total volume of shares traded. See the given attached R code image.

What does 'profit' represent?

a)

Total profit gained

b)

Total revenue generated

c)

Average profit per share

d)

Total expenses

9.

Which of the following is true for a VECTOR in R?

a)

It is a homogeneous 1-dimensional data structure

b)

It is a heterogeneous 1-dimensional data structure

c)

It is homogeneous 2-dimensional data structure

d)

It is a heterogeneous 2-dimensional data structure

10.

Which of the following function cannot be used to import a csv file in R?

a)

read.table()

b)

read.csv()

c)

read_excel()

d)

All of the above

11.

What does 'dplyr' do in R Language?

a)

dplyr is a new package which provides a set of tools for efficiently manipulating datasets in R

b)

dplyr is faster, has a more consistent API and should be easier to use

c)

Focusing on data frames

d)

All of the above

12.

These are the generic data objects of R which are used to store the tabular data. This made up of three principal components, the data, rows, and columns.

a)

Array

b)

Data Frames

c)

Lists

d)

Factors

13.

Which tidyverse package contains a set of functions, such as select(), that help with data manipulation?

a)

forcats

b)

readr

c)

ggplot2

d)

dplyr

14.

An object used where R interpreter can pass control along with arguments and produces output by executing valid R commands that inside of it. This is usually useful when you want to perform a certain task multiple time.

a)

Function

b)

Operation

c)

Vectors

d)

Command

15.

Which of the following statements is true about the difference between matrices and data frames in R?

a)

Matrices can hold mixed data types, while data frames cannot

b)

Data frames can have column names, while matrices cannot

c)

Matrices support row names, while data frames do not

d)

Data frames are two-dimensional, while matrices can have multiple dimensions

16.

Which of the following terms best describes the R Programming language?

a)

Open-ended

b)

Open-data

c)

Data-centric

d)

Closed-source

17.

What type of software application is RStudio?

a)

Data Visualization Tool

b)

Source Editor

c)

Database

d)

Integrated Development Environment

18.

The following statements are the reason why many data analysts prefer to use a R programming language, EXCEPT?

a)

To easily reproduce and share an analysis

b)

To clarify the steps of an analysis

c)

To save time

d)

To choose a topic for analysis

19.

Which of the following function gives information about top level data?

a)

tail()

b)

head()

c)

summary()

d)

None of the above

20.

In R the following are all basic “atomic” data types, EXCEPT?

a)

real

b)

character

c)

raw

d)

list

21.

If we execute the expression x <- 6 in R, what is the class of the object ‘x’ as determined by the ‘class()’ function?

a)

real

b)

complex

c)

integer

d)

number

22.

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

a)

numeric

b)

character

c)

float

d)

logical

23.

If we have two vectors x <- c(1, 3, 5) and y <- c(3, 2, 10), what will be produced by the expression rbind(x, y)?

a)

A vector of length 3

b)

A 3x3 matrix

c)

A 2x2 matrix

d)

A matrix of 2 rows and 3 columns

24.

Suppose we have a list defined as x <- list(2, ‘a’, ‘b’, TRUE). What does x[[1]] give us?

a)

A numeric vector of length 1 and character vector containing the element 2

b)

A numeric vector containing the element 2

c)

A list containing a numeric vector of length 1

d)

A list containing the number 2

25.

Which of the following R code will correctly compute and display output of “3 5 5 7”?

a)

b)

c)

d)

26.

From the given dataset (airquality.csv) by your instructor, which of the following R codes correctly determines the count of missing values in the "Ozone" column of the "airquality" dataset?

a)

b)

c)

d)

27.

Which of the following R codes correctly extracts a subset of rows from the "airquality" dataset where the Ozone values are above 31 and the Temp values are above 90 (NA’s excluded)?

a)

b)

c)

d)

28.

From the given dataset (airquality.csv) by your instructor, what is the mean of “Temp” when “Month” is equal to 6? (You can use RStudio to code and know the mean)

a)

90.2

b)

85.6

c)

75.3

d)

79.1

29.

From the given dataset (airquality.csv) by your instructor, what was the maximum “Ozone” value in the month of May (i.e. Month is equal to 5)?

a)

100

b)

115

c)

18

d)

97

30.

The following R code (see attached image) produced an error in R. Why?

a)

There are no elements in ‘x’ that are greater than 5

b)

We cannot set ‘x’ to be 0 because ‘x’ is a vector and 0 is a scalar

c)

‘x’ is a vector of length 10 and ‘if’ can only test a single logical statement

d)

The expression uses only curly braces

31.

We have a data frame named “employee” with column “Status”. The column “Status” has only 3 categorical values: “single”, “married”, and “divorced”. Which command/code correctly subsets a dataframe "df" to select rows where "Status" is "single" or "married”?

a)

subset(df, Status == "single" & Status == “married”)

b)

filter(df, Status == "single" | Status == “married”)

c)

df[df$Status == "single" | df$Age >= 25, ]

d)

df[Status == "single" & Status == “married”, ]

32.

We have a data frame named "voters" with columns "Name", "Age", and "Region". What code would you use to subset the data frame to include only the rows where the voters' age is greater than 18?

a)

voters[voters$Age < 18, ]

b)

voters[voters$Age > 20, ]

c)

subset(voters, Age < 20)

d)

subset(voters, Age > 20)

33.

Which of the following statements accurately describes the R package tidyverse?

a)

tidyverse is a collection of packages that primarily focuses on data manipulation, visualization, and programming with tidy data principles.

b)

tidyverse is a package used specifically for creating statistical models and conducting hypothesis testing in R.

c)

tidyverse is designed exclusively for machine learning tasks such as clustering and classification in R.

d)

tidyverse is primarily used for handling big data and performing distributed computing in R.

34.

Which Tidyverse package is used for data cleaning and wrangling?

a)

ggplot2

b)

tidyr

c)

readr

d)

dplyr

35.

Which of the following is NOT a core Tidyverse package?

a)

purr

b)

tibble

c)

stringr

d)

forcats

36.

From the given R code (see attached image), What is the difference between the matrix and the tibble?

a)

The ‘tibbl’e has named variables (columns) and the ‘matrix’ does not name the columns

b)

The ‘tibble’ retains the original data type and the ‘matrix’ converts the data types

c)

‘matrix’ is a base R function and ‘tibble’ is a tidyverse function

d)

All of the above

37.

Let us say, suppose a dataset “student” with columns: "Name", "Age", "Grade", we want to filter students aged above 20 and having a grade above B. Which code accomplishes this?

a)

filter(students, Age > 20 & Grade > "B")

b)

filter(students, Age > 20, Grade > "B")

c)

filter(students, Age > 20, Grade %in% c("B", "C", "D", "F"))

d)

filter(students, Age > 20 & Grade %in% c("A", "B"))

38.

We have a dataset “sales_data” with columns: "ProductID", "ProductName", "Price", "Quantity". Then we want to select only the "ProductName" and "Price" columns. Using tidyverse package, which of the following code is correct to do this?

a)

select(sales_data, c(2, 3))

b)

select(sales_data, c("ProductName", "Price"))

c)

filter(sales_data, matches("ProductName|Price"))

d)

filter(sales_data, c("ProductName", "Price"))

39.

In a dataset “sale_data” containing columns: "Product", "Price", and "Quantity", we aim to sort the products by the highest sales value (Price * Quantity). Which R code accomplishes this task under tidyverse?

a)

arrange(sales_data, desc(Price * Quantity))

b)

arrange(sales_data, (Price)(Quantity))

c)

arrange(sales_data, Price, Quantity)

d)

arrange(sales_data, Price * Quantity)

40.

In a dataset “employee” comprising columns: "Name", "Salary", and "Department". You wish to add a new column "Bonus" that awards a 10% bonus to employees in the "IT" department. Which R code accomplishes this task under tidyverse?

a)

mutate(employees, Bonus = case_when(Department == "IT" ~ Salary * 0.10, TRUE ~ Salary))arrange(sales_data, (Price)(Quantity))

b)

mutate(employees, Bonus = if(Department == "IT") Salary * 0.10 else Salary)

c)

mutate(employees, Bonus = ifelse(Department == "IT", Salary * 0.10, Salary))

d)

mutate(employees, Bonus = if(Department %in% "IT") Salary * 0.10 else Salary)

41.

What will be the output of the given R code (see attached image)?

a)

1 4 9 16 25

b)

1 2 3 4 5

c)

2 4 6 8 10

d)

1 3 5 7 9

42.

One of the control statements in R that iterates over a block of code and does not use a condition to exit the loop instead it looks for a break statement.

a)

For loop

b)

While loop

c)

Iteration loop

d)

Repeat loop

43.

Which function in R is used to apply a function to the rows or columns of a matrix or data frame?

a)

apply()

b)

lapply()

c)

sapply()

d)

tapply()

44.

What is the purpose of the 2nd argument value when we use ‘apply()’ function?

a)

A function to be applied

b)

A matrix or dataframe

c)

A vector giving the subscripts which the function will be applied

d)

A factor or a list of factors

45.

Under the apply function family, we use this to apply a given function in a multi-argument form to corresponding elements of multiple vectors or lists. It can handle multiple vectors or lists simultaneously, applying the specified function in a pairwise manner across these structures

a)

apply()

b)

lapply()

c)

sapply()

d)

mapply()

46.

The ‘next’ statement is used to skip the current iteration of a loop and move to the next iteration, but it does not terminate the loop

a)

TRUE

b)

FALSE

47.

Using ‘ifelse()’ in R, a vectorized conditional function, results in nested conditions

a)

TRUE

b)

FALSE

48.

In R, the ‘while’ loop always executes at least once, even if the condition is initially false.

a)

TRUE

b)

FALSE

49.

‘lapply()’ and ‘sapply()’ in R can both be used to apply a function over a list.

a)

TRUE

b)

FALSE

50.

Understanding and leveraging the Apply family functions empower R programmers to handle diverse datasets and automate repetitive tasks efficiently.

a)

TRUE

b)

FALSE