This exercise is designed to help you practice basic R programming and data manipulation using the dplyr
package from the Tidyverse. Follow the instructions below and complete the tasks in your R environment.
- Install and load the Tidyverse: If you haven't already, install the
tidyverse
package and load it into your R session.
install.packages("tidyverse")
library(tidyverse)
- Create a data frame: Use the following code to create a sample data frame for this exercise.
employees <- data.frame(
ID = 1:6,
Name = c("Alice", "Bob", "Charlie", "David", "Eve", "Frank"),
Age = c(25, 30, 35, 40, 45, 50),
Department = c("HR", "IT", "Finance", "IT", "HR", "Finance"),
Salary = c(50000, 60000, 70000, 80000, 55000, 75000)
)
This data frame contains information about employees, including their ID, name, age, department, and salary.
- Print the employees data frame to the console.
- Use the str() function to inspect the structure of the data frame.
- Use the summary() function to get a summary of the data.
- Filter rows: Create a new data frame that includes only employees who work in the "IT" department.
- Select columns: Create a new data frame that includes only the Name and Salary columns.
- Add a new column: Add a new column called Bonus that calculates a 10% bonus for each employee based on their salary.
- Sort rows: Sort the employees data frame by Salary in descending order.
- Summarize data: Calculate the average salary for each department.
- Group and summarize: Group the data by Department and calculate the total salary expenditure for each department.
- Filter and mutate: Create a new data frame that includes only employees older than 30 and adds a column called Experience that assumes each employee has Age - 25 years of experience.
- Combine operations: Create a new data frame that includes employees from the "HR" department, adds a Bonus column (10% of salary), and sorts the data by Bonus in descending order.
- Visualize data: Use ggplot2 to create a bar plot showing the total salary expenditure by department.
- Submitted notebook (or file) with your responses to each of the exercises.
- Upon completion, add your deliverables to git.
- Then commit git and push your branch to the remote.
- Make a pull request and paste the PR link in the submission field in the Student Portal.
Good luck!