Chapter 11 Aggregating Data
11.1 Single Column
11.1.1 Get the unique values within a column
Description | |
---|---|
Method to get all unique values within a single column of a dataframe |
Ingredients | |
---|---|
Package | Data |
readr |
sample.csv |
Preparation
<- readr::read_csv("C:/data/sample.csv") df
Sample Instructions
::function(data, column_name) package
Actual Instructions
::distinct(df, species) dplyr
11.1.2 Get the unique values and their frequency within a column
Description | |
---|---|
Method to get all unique values and their frequency within a single column of a dataframe |
Ingredients | |
---|---|
Package | Data |
readr |
sample.csv |
Preparation
<- readr::read_csv("C:/data/sample.csv") df
Sample Instructions
::function(data, column_name) %>%
package::function() %>%
package::function() package
Actual Instructions
::group_by(df, species) %>%
dplyr::tally() %>%
dplyr::ungroup() dplyr
11.1.3 Get the unique values and their frequency within a column while ordering from the smallest value
Description | |
---|---|
Method to get all unique values and ordering their frequency from smallest to largest within a single column of a dataframe |
Ingredients | |
---|---|
Package | Data |
readr |
sample.csv |
Preparation
<- readr::read_csv("C:/data/sample.csv") df
Sample Instructions
::function(data, column_name) %>%
package::function() %>%
package::function() %>%
package::function(n) package
Actual Instructions
::group_by(df, species) %>%
dplyr::tally() %>%
dplyr::ungroup() %>%
dplyr::arrange(n) dplyr
11.1.4 Get the unique values and their frequency within a column while ordering from the largest value
Description | |
---|---|
Method to get all unique values and ordering their frequency from largest to smallest within a single column of a dataframe |
Ingredients | |
---|---|
Package | Data |
readr |
sample.csv |
Preparation
<- readr::read_csv("C:/data/sample.csv") df
Sample Instructions
::function(data, column_name) %>%
package::function() %>%
package::function() %>%
package::function(function(n)) package
Actual Instructions
::group_by(df, species) %>%
dplyr::tally() %>%
dplyr::ungroup() %>%
dplyr::arrange(desc(n)) dplyr
11.2 Multiple Columns
11.2.1 Get the unique values in multiple columns
Description | |
---|---|
Method to get all unique values in multiple columns of a dataframe |
Ingredients | |
---|---|
Package | Data |
readr |
sample.csv |
Preparation
<- readr::read_csv("C:/data/sample.csv") df
Sample Instructions
::function(data, column_name1, column_name2) package
Actual Instructions
::distinct(df, species, type) dplyr
11.2.2 Get the unique values and their frequency in multiple columns
Description | |
---|---|
Method to get all unique values and their frequency in multiple columns of a dataframe |
Ingredients | |
---|---|
Package | Data |
readr |
sample.csv |
Preparation
<- readr::read_csv("C:/data/sample.csv") df
Sample Instructions
::function(data, column_name1, column_name2) %>%
package::function() %>%
package::function() package
Actual Instructions
::distinct(df, species, type) %>%
dplyr::tally() %>%
dplyr::ungroup() dplyr
11.2.3 Get the unique values and their frequency in multiple columns while ordering the smallest value in a column
Description | |
---|---|
Method to get all unique values and ordering their frequency from smallest to largest within a multiple columns of a dataframe |
Ingredients | |
---|---|
Package | Data |
readr |
sample.csv |
Preparation
<- readr::read_csv("C:/data/sample.csv") df
Sample Instructions
::function(data, column_name1, column_name2) %>%
package::function() %>%
package::function() package
Actual Instructions
::distinct(df, species, type) %>%
dplyr::tally() %>%
dplyr::ungroup() %>%
dplyr::arrange() dplyr
11.2.4 Get the unique values and their frequency in multiple columns while ordering the largest value in a column
Description | |
---|---|
Method to get all unique values and ordering their frequency from largest to smallest within a single column of a dataframe |
Ingredients | |
---|---|
Package | Data |
readr |
sample.csv |
Preparation
<- readr::read_csv("C:/data/sample.csv") df
Sample Instructions
::function(data, column_name1, column_name2) %>%
package::function() %>%
package::function(function(n)) package
Actual Instructions
::distinct(df, species, type) %>%
dplyr::tally() %>%
dplyr::ungroup() %>%
dplyr::arrange(desc(n)) dplyr