# Defining the data
employee_id <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
name <- c("Ted", "James", "Ann", "Peter", "Alex", "Emily", "Lisa", "Emma", "Lee", "Mark")
department <- c("Sales", "HR", "Finance", "Marketing", "IT", "Sales", "HR", "Finance", "Marketing", "IT")
age <- c(32, 28, 35, 30, 38, 29, 31, 33, 36, 27)
salary <- c(50000, 45000, 60000, 55000, 650000, 48000, 58000, 62000, 43000, 52000)
years_of_experience <- c(5, 3, 8, 4, 10, 2, 6, 7, 9, 1)
# Creating the data frame
Employees <- data.frame(
Employee_ID = employee_id,
Name = name,
Department = department,
Age = age,
Salary = salary,
Years_Of_Experience = years_of_experience
)
# Displaying the data frame
print(Employees)
## Employee_ID Name Department Age Salary Years_Of_Experience
## 1 1 Ted Sales 32 50000 5
## 2 2 James HR 28 45000 3
## 3 3 Ann Finance 35 60000 8
## 4 4 Peter Marketing 30 55000 4
## 5 5 Alex IT 38 650000 10
## 6 6 Emily Sales 29 48000 2
## 7 7 Lisa HR 31 58000 6
## 8 8 Emma Finance 33 62000 7
## 9 9 Lee Marketing 36 43000 9
## 10 10 Mark IT 27 52000 1
# Displaying the number of employees
num_employees <- nrow(Employees)
print(num_employees)
## [1] 10
# Displaying the average salary
avg_salary <- mean(Employees$Salary)
print(avg_salary)
## [1] 112300
# Displaying the highest paid salary
highest_salary <- max(Employees$Salary)
print(highest_salary)
## [1] 650000
# Displaying the number of employees in each department
dept_counts <- table(Employees$Department)
print(dept_counts)
##
## Finance HR IT Marketing Sales
## 2 2 2 2 2
# Displaying the total years of experience
total_experience <- sum(Employees$Years_Of_Experience)
print(total_experience)
## [1] 55
# Finding the index of the highest salary
index_highest_salary <- which.max(Employees$Salary)
print(index_highest_salary)
## [1] 5
# Extracting the name of the most paid employee
most_paid_employee <- Employees$Name[index_highest_salary]
print(most_paid_employee)
## [1] "Alex"