R Programming: Create and Summarize employee Dataframes
Write a R program to create a Dataframes which contain details of 5 employees and display summary of the data.
Sample Solution :
R Programming Code :
# Create a data frame named 'Employees' with details of 5 employees
Employees = data.frame(
# Employee names
Name = c("Anastasia S", "Dima R", "Katherine S", "JAMES A", "LAURA MARTIN"),
# Employee genders
Gender = c("M", "M", "F", "F", "M"),
# Employee ages
Age = c(23, 22, 25, 26, 32),
# Employee designations
Designation = c("Clerk", "Manager", "Exective", "CEO", "ASSISTANT"),
# Employee Social Security Numbers (SSN)
SSN = c("123-34-2346", "123-44-779", "556-24-433", "123-98-987", "679-77-576")
)
# Print a message indicating the summary of the data
print("Summary of the data:")
# Print a summary of the 'Employees' data frame, which includes basic statistics
print(summary(Employees))
Output:
[1] "Summary of the data:" Name Gender Age Designation Length:5 Length:5 Min. :22.0 Length:5 Class :character Class :character 1st Qu.:23.0 Class :character Mode :character Mode :character Median :25.0 Mode :character Mean :25.6 3rd Qu.:26.0 Max. :32.0 SSN Length:5 Class :character Mode :character
Explanation:
- Create a Dataframe:
- Employees = data.frame(...) initializes a dataframe named Employees.
- Name=c("Anastasia S","Dima R","Katherine S", "JAMES A","LAURA MARTIN") specifies the names of the employees.
- Gender=c("M","M","F","F","M") specifies the gender for each employee.
- Age=c(23,22,25,26,32) lists the ages of the employees.
- Designation=c("Clerk","Manager","Exective","CEO","ASSISTANT") includes the job titles of the employees.
- SSN=c("123-34-2346","123-44-779","556-24-433","123-98-987","679-77-576") provides the Social Security Numbers.
- Print Summary:
- print("Summary of the data:") prints a message indicating the upcoming summary.
- print(summary(Employees)) displays a summary of the dataframe, including:
- Count and distribution of values for each column.
- Basic statistics for numeric columns (e.g., Age).
R Programming Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a R program to create a Data Frames which contain details of 5 employees and display the details.
Next: Write a R program to create the system's idea of the current date with and without time.
Test your Programming skills with w3resource's quiz.
What is the difficulty level of this exercise?
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics