NEW
Font size
WorksheetsBSCS 4-3 - Midterm Exam (Jan. 6, 2024)
Total questions: 50
Worksheet time: 25mins
What best describes R in programming?
A programming language for statistics and data analysis
A web development language
An operating system
A gaming software
Which of the following is the correct sequence for installing R and R Studio?
Install R first, then R Studio
Install R Studio first, then R
Installation order doesn't matter
Install both simultaneously
What is the purpose of the 'Environment' tab in RStudio?
To display all installed packages
To manage files and folders
To view objects, variables, and their values
To write and execute code
Which operator is used in R for exponentiation?
**
//
%
^
What's the primary purpose of a function in R?
Plotting graphs
Storing datasets
Reusing code and performing specific tasks
Writing comments in code
Which of the following R code will correctly compute and display output of 45?
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?
Total loaves available
Total expenses
Average price per loaf sold
Total revenue generated
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?
Total profit gained
Total revenue generated
Average profit per share
Total expenses
Which of the following is true for a VECTOR in R?
It is a homogeneous 1-dimensional data structure
It is a heterogeneous 1-dimensional data structure
It is homogeneous 2-dimensional data structure
It is a heterogeneous 2-dimensional data structure
Which of the following function cannot be used to import a csv file in R?
read.table()
read.csv()
read_excel()
All of the above
What does 'dplyr' do in R Language?
dplyr is a new package which provides a set of tools for efficiently manipulating datasets in R
dplyr is faster, has a more consistent API and should be easier to use
Focusing on data frames
All of the above
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.
Array
Data Frames
Lists
Factors
Which tidyverse package contains a set of functions, such as select(), that help with data manipulation?
forcats
readr
ggplot2
dplyr
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.
Function
Operation
Vectors
Command
Which of the following statements is true about the difference between matrices and data frames in R?
Matrices can hold mixed data types, while data frames cannot
Data frames can have column names, while matrices cannot
Matrices support row names, while data frames do not
Data frames are two-dimensional, while matrices can have multiple dimensions
Which of the following terms best describes the R Programming language?
Open-ended
Open-data
Data-centric
Closed-source
What type of software application is RStudio?
Data Visualization Tool
Source Editor
Database
Integrated Development Environment
The following statements are the reason why many data analysts prefer to use a R programming language, EXCEPT?
To easily reproduce and share an analysis
To clarify the steps of an analysis
To save time
To choose a topic for analysis
Which of the following function gives information about top level data?
tail()
head()
summary()
None of the above
In R the following are all basic “atomic” data types, EXCEPT?
real
character
raw
list
If we execute the expression x <- 6 in R, what is the class of the object ‘x’ as determined by the ‘class()’ function?
real
complex
integer
number
What is the class of the object defined by the expression x <- c(4, “a”, TRUE)?
numeric
character
float
logical
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 vector of length 3
A 3x3 matrix
A 2x2 matrix
A matrix of 2 rows and 3 columns
Suppose we have a list defined as x <- list(2, ‘a’, ‘b’, TRUE). What does x[[1]] give us?
A numeric vector of length 1 and character vector containing the element 2
A numeric vector containing the element 2
A list containing a numeric vector of length 1
A list containing the number 2
Which of the following R code will correctly compute and display output of “3 5 5 7”?
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?
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)?
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)
90.2
85.6
75.3
79.1
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)?
100
115
18
97
The following R code (see attached image) produced an error in R. Why?
There are no elements in ‘x’ that are greater than 5
We cannot set ‘x’ to be 0 because ‘x’ is a vector and 0 is a scalar
‘x’ is a vector of length 10 and ‘if’ can only test a single logical statement
The expression uses only curly braces
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”?
subset(df, Status == "single" & Status == “married”)
filter(df, Status == "single" | Status == “married”)
df[df$Status == "single" | df$Age >= 25, ]
df[Status == "single" & Status == “married”, ]
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?
voters[voters$Age < 18, ]
voters[voters$Age > 20, ]
subset(voters, Age < 20)
subset(voters, Age > 20)
Which of the following statements accurately describes the R package tidyverse?
tidyverse is a collection of packages that primarily focuses on data manipulation, visualization, and programming with tidy data principles.
tidyverse is a package used specifically for creating statistical models and conducting hypothesis testing in R.
tidyverse is designed exclusively for machine learning tasks such as clustering and classification in R.
tidyverse is primarily used for handling big data and performing distributed computing in R.
Which Tidyverse package is used for data cleaning and wrangling?
ggplot2
tidyr
readr
dplyr
Which of the following is NOT a core Tidyverse package?
purr
tibble
stringr
forcats
From the given R code (see attached image), What is the difference between the matrix and the tibble?
The ‘tibbl’e has named variables (columns) and the ‘matrix’ does not name the columns
The ‘tibble’ retains the original data type and the ‘matrix’ converts the data types
‘matrix’ is a base R function and ‘tibble’ is a tidyverse function
All of the above
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?
filter(students, Age > 20 & Grade > "B")
filter(students, Age > 20, Grade > "B")
filter(students, Age > 20, Grade %in% c("B", "C", "D", "F"))
filter(students, Age > 20 & Grade %in% c("A", "B"))
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?
select(sales_data, c(2, 3))
select(sales_data, c("ProductName", "Price"))
filter(sales_data, matches("ProductName|Price"))
filter(sales_data, c("ProductName", "Price"))
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?
arrange(sales_data, desc(Price * Quantity))
arrange(sales_data, (Price)(Quantity))
arrange(sales_data, Price, Quantity)
arrange(sales_data, Price * Quantity)
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?
mutate(employees, Bonus = case_when(Department == "IT" ~ Salary * 0.10, TRUE ~ Salary))arrange(sales_data, (Price)(Quantity))
mutate(employees, Bonus = if(Department == "IT") Salary * 0.10 else Salary)
mutate(employees, Bonus = ifelse(Department == "IT", Salary * 0.10, Salary))
mutate(employees, Bonus = if(Department %in% "IT") Salary * 0.10 else Salary)
What will be the output of the given R code (see attached image)?
1 4 9 16 25
1 2 3 4 5
2 4 6 8 10
1 3 5 7 9
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.
For loop
While loop
Iteration loop
Repeat loop
Which function in R is used to apply a function to the rows or columns of a matrix or data frame?
apply()
lapply()
sapply()
tapply()
What is the purpose of the 2nd argument value when we use ‘apply()’ function?
A function to be applied
A matrix or dataframe
A vector giving the subscripts which the function will be applied
A factor or a list of factors
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
apply()
lapply()
sapply()
mapply()
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
TRUE
FALSE
Using ‘ifelse()’ in R, a vectorized conditional function, results in nested conditions
TRUE
FALSE
In R, the ‘while’ loop always executes at least once, even if the condition is initially false.
TRUE
FALSE
‘lapply()’ and ‘sapply()’ in R can both be used to apply a function over a list.
TRUE
FALSE
Understanding and leveraging the Apply family functions empower R programmers to handle diverse datasets and automate repetitive tasks efficiently.
TRUE
FALSE
