Hello again! Welcome to another crucial part of mastering data frames in R. You've already learned how to create, inspect, and manipulate data frames. Now, it's time to elevate your skills by diving into data frame calculations. This lesson will be a significant step in your data analysis journey.
In this lesson, you'll discover how to perform essential calculations on data frames, such as:
Here's a glimpse of everything we'll be doing in this lesson:
R1# Create a data frame 2df <- data.frame( 3 ID = 1:5, 4 Name = c("John", "Jane", "Alex", "Emily", "David"), 5 Age = c(28, 22, 35, 29, 40), 6 Salary = c(50000, 60000, 70000, 80000, 90000) 7) 8 9# Calculate mean age 10mean_age <- mean(df$Age) 11print(mean_age) 12 13# Calculate maximum and minimum salary 14max_salary <- max(df$Salary) 15min_salary <- min(df$Salary) 16 17print(max_salary) 18print(min_salary) 19 20# Calculate median salary 21median_salary <- median(df$Salary) 22print(median_salary) 23 24# Calculate the number of names 25num_names <- length(df$Name) 26print(num_names)
As you can see, these calculations will help you gain deeper insights from your data frames.
Understanding data frame calculations is vital for several reasons:
By mastering these calculations, you'll not only enhance your ability to analyze data, but you'll also be able to present your findings more effectively. Ready to dive in? Let’s begin the practice section and boost your data analysis skills!