R Foundations Quiz
This exercise is designed to test your knowledge of R Foundations and prepare you for our upcoming R Intermediate session.
Please make use of the R resource website along with the session slides if you need resources to learn/revise.
Using the datasets sent in the e-mail separately, please follow the below instructions carefully to answer the exercise questions.
Please Note: Since this test is a prerequisite to the R Intermediate session, you are expected to finish it to be eligible for the R Intermediate session.
All the best! π
Dataset Description π
- Retail data: Comprises info about users who visited an e-commerce site such as each userβs profile and site activity.
- Sales data and Customer Info data: Describes info about sales of an automobile retailer and the associated customer details.
Instructions β
Load the required libraries:
tidyverseandreadxl- Load the datasets and save as following:
- Retail data as
retail - Sales data as
sales - Cust info data as
cust_info
- Retail data as
Attempt the exercise questions given below using your R Studio console and click here to submit your answers.
Exercise Questions: Theory π
Q1. The R language is based on which programming language?
Q2. If you execute the expression x = 52 in R, what is the class of the object x as determined by the class() function?
Q3. What is the class of the object defined by the expression m = c(100, "z", FALSE)?
Q4. If you have two vectors p = c(2, 5, 7) and q = c(8, 4, 12), what is produced by the expression rbind(p, q)?
Q5. Suppose you have a vector k = 1:4 and a vector l = 2. What is produced by the expression k + l?
Q6. Suppose you have a vector b = c(3, 5, 1, 10, 12, 6). How would you set all elements of this vector that are less than 9 to be equal to zero?
Exercise Questions: Case Study π
Data Exploration: Use the retail dataset
Q7. What is the class type of the retail data set?
Q8. How many observations (rows) and variables (columns) are in the retail data set?
Q9. What are the names of the last 3 columns in the retail data set?
Q10. What is the class of the state column in the retail data set?
Q11. What is the class of the num_visits column in the retail data set?
Q12. How many unique countries are there in the country column of retail dataset?
Data Wrangling: Use the retail dataset
Q13. What is the total number of visits which the site had?
Q14. Among males and females, which group had the highest visits?
Q15. Calculate the average number of site visits by parents in the retail dataset.
Q16. Among the US states, which state had the most number of visits and how many?
Data wrangling: Use the sales and cust_info dataset
Q17. Create a new variable in the sales dataset called revenue. Which month witnessed the highest revenue? (Hint revenue = quantity * price_each)
Q18. Calculate the yearly revenue. What was the total revenue in 2003?
Q19. Left join cust_info dataset with the sales dataset using the ID column and save the new dataset as sales_customer. How many rows and columns are in sales_customer?
Q20. Use the sales_customer dataset to find the total quantity sold in Norway.
Q21. In which state within sales_customer dataset was the total quantity equal to 11,986?