Slip7
Write an R program to create a Dataframes which contain details of 5
employees and display the details in ascending order.
Employees = data.frame(Name=c("Archana","Doly","Raja",
"zinat","Lila"),
Gender=c("M","M","F","F","M"),
Age=c(23,65,34,24,45),
Designation=c("Clerk","Manager","HR","CEO","ASSISTANT"), mobile=c("9876567865","8889765454","9879065434","612398987","88867977576")
)
print("Details of
the employees:")
print(Employees)
employee_data <-
data.frame(
EmployeeID = c(1, 2, 3, 4, 5),
Name = c("John", "Alice",
"Bob", "Eve", "Charlie"),
Age = c(28, 25, 32, 22, 30),
Salary = c(50000, 55000, 60000, 48000, 52000),
Department = c("HR", "IT",
"Finance", "Marketing", "Sales")
)
# Display the original
data frame
cat("Original Data
Frame:\n")
print(employee_data)
# Sort the data frame by
EmployeeID in ascending order
sorted_employee_data <-
employee_data[order(employee_data$EmployeeID), ]
# Display the sorted data
frame
cat("\nData Frame
Sorted by EmployeeID in Ascending Order:\n")
print(sorted_employee_data)
Output
Data Frame Sorted by
EmployeeID in Ascending Order:
>
print(sorted_employee_data)
EmployeeID
Name Age Salary Department
1 1
John 28 50000
HR
2 2
Alice 25 55000
IT
3 3
Bob 32 60000
Finance
4 4
Eve 22 48000
Marketing
5 5 Charlie 30
52000 Sales