summarize()
This lesson is called summarize(), part of the Fundamentals of R course. This lesson is called summarize(), part of the Fundamentals of R course.
Transcript
Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.
Loading transcript...
View code shown in video
# Load Packages -----------------------------------------------------------
library(tidyverse)
# Import Data -------------------------------------------------------------
penguins <-
read_csv("penguins.csv")
# summarize() -------------------------------------------------------------
# With summarize(), we can go from a complete dataset down to a summary.
# We use any of the summary functions with summarize().
# Here's how we calculate the mean bill length.
penguins |>
summarize(mean_bill_length = mean(bill_length_mm))
# This doesn't work! Notice what the result is.
# We need to add na.rm = TRUE to tell R to drop NA values.
penguins |>
summarize(mean_bill_length = mean(bill_length_mm, na.rm = TRUE))
# Another option is to drop NA values before calling summarize().
penguins |>
drop_na(bill_length_mm) |>
summarize(mean_bill_length = mean(bill_length_mm))
# We can have multiple arguments in each usage of summarize().
penguins |>
summarize(
mean_bill_length = mean(bill_length_mm, na.rm = TRUE),
max_bill_depth = max(bill_depth_mm, na.rm = TRUE)
)
penguins |>
summarize(mean_bill_length = mean(bill_length_mm, na.rm = TRUE)) |>
summarize(mean_bill_depth = mean(bill_depth_mm, na.rm = TRUE))
Your Turn
# Load Packages -----------------------------------------------------------
# Load the tidyverse package
library(tidyverse)
# Import Data -------------------------------------------------------------
penguins <- read_csv("penguins.csv")
# Calculate the weight of the heaviest penguin.
# Don't forget to drop NAs!
# YOUR CODE HERE
# Calculate the minimum and maximum weight of penguins in the dataset.
# YOUR CODE HERE
Learn More
To learn more about the summarize() function, check out Chapter 3 of R for Data Science.
Have any questions? Put them below and we will help you out!
Course Content
33 Lessons
1
The Grammar of Graphics
04:36
2
Scatterplots
03:40
3
Histograms
04:51
4
Bar Charts
04:53
5
Setting color and fill Aesthetic Properties
02:43
6
Setting color and fill Scales
05:12
7
Setting x and y Scales
02:58
8
Adding Text to Plots
05:50
9
Plot Labels
02:59
10
Themes
02:10
11
Facets
02:56
12
Save Plots
02:49
13
Bring it All Together (Data Visualization)
06:14
You need to be signed-in to comment on this post. Login.