Uploaded by paul.castermans

S2-R-week-6-mock test

advertisement
R week 6 mock test - semester 2 Business - spring 2020
Date: 18th March 2021
Instructions
Time - 1 hour
Section A: MCQ: each question carries 1 point
Section B: each question carries 2 point
•
Use the list of functions at the end to write R code for the questions in section B.
Section A
1.
What is a tibble?
a. An aesthetic mapping
b. An alternative to the data frame x
c. A way to facet data
d. A way to pipe data
2.
Look at the following piece of code.
ID <- c(1, 2, 3)
name <- c("AB", "CD", "EF")
df <- data.frame(ID, name)
names(df) <- c("Student ID", "Student name")
What is the effect of the last statement?
a.
b.
c.
Assigns meaningful names to the variables in the data frame. x
Assigns meaningful names to the observations in the data frame.
Changes the data types of the variables in the data frame.
d. Extracts the columns “StudentID” and “Student name“ from the data frame.
3.
Which of the following is not a requirement of a tidy data set?
a. Each variable must have a meaningful name. x
b. Each variable must have its own column.
c. Each observation must have its own row.
d. Each value must have its own cell.
Section B
1.
Consider the following data set storing the bank balance of customers at the end of every financial
quarter. (Each year has four quarters of 3 months each).
CustID
Year
Quarter
Balance
101
2001
1
NA
101
2001
2
1020
101
2001
3
1013
101
2001
4
900
101
2002
1
1034
101
2002
2
2000
101
2002
4
1800
Identify all the misssing values and categorise them as explicit or implicit
Quarter 3 of 2002 is implicit missing
The Balance for the first quarter of 2001 is explicit missing
2.
Is this data set tidy? Why/why not? And if not, how would you make it tidy (just describe in words,
need not give R code).
This Data set is not tidy because, because the column passpercentage needs to be seperated into two
columns percentage and pass. Each cell is suppose to have one 1 value
Year
University
Passpercentage
2000
Fontys
234/250
2000
TU/e
321/356
2001
Fontys
200/261
2001
TU/e
434/500
2002
Fontys
301/329
2002
TU/e
608/666
3. What business question does the following chunk answer?
temp <- tribble(
~place, ~day, ~temp,
"Eidhoven", 1, 20,
NA, 2, NA,
"Maastricht", 1, 19,
NA, 2, NA,
NA, 2, 18)
temp
(temp %>% fill(place, temp))
The above chunk is creating a table that shows the temperature of each day at a given place
4. Give the output of the chunk for question (3) as precisely as possible.
The output will be a table that shows different places, days and temperatures
with some missing values for place and temperature in each day
5. The following piece of code creates a data frame bankbalance to store the bank
balance of customers at the end of every financial quarter. (Each year has four
quarters of 3 months each). How will you tidy up this data set given the fact that
each year has just 4 quarters? Write the R code below.
CustID
101
101
101
101
101
101
101
Year
2001
2001
2001
2001
2002
2002
2002
Quarter
1
2
3
4
1
2
4
Balance
1500
2000
2409
1800
12000
17000
19000
Bankbalance %>%
List of functions
These are all the functions you need to answer the questions in section B (choose from the
below).
•
pivot_longer
•
pivot_wider
•
separate
•
unite
Download