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
df <- readr::read_csv("C:/data/sample.csv")Sample Instructions
package::function(data, column_name)Actual Instructions
dplyr::distinct(df, species)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
df <- readr::read_csv("C:/data/sample.csv")Sample Instructions
package::function(data, column_name) %>%
package::function() %>%
package::function()Actual Instructions
dplyr::group_by(df, species) %>%
dplyr::tally() %>%
dplyr::ungroup()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
df <- readr::read_csv("C:/data/sample.csv")Sample Instructions
package::function(data, column_name) %>%
package::function() %>%
package::function() %>%
package::function(n)Actual Instructions
dplyr::group_by(df, species) %>%
dplyr::tally() %>%
dplyr::ungroup() %>%
dplyr::arrange(n)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
df <- readr::read_csv("C:/data/sample.csv")Sample Instructions
package::function(data, column_name) %>%
package::function() %>%
package::function() %>%
package::function(function(n))Actual Instructions
dplyr::group_by(df, species) %>%
dplyr::tally() %>%
dplyr::ungroup() %>%
dplyr::arrange(desc(n))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
df <- readr::read_csv("C:/data/sample.csv")Sample Instructions
package::function(data, column_name1, column_name2)Actual Instructions
dplyr::distinct(df, species, type)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
df <- readr::read_csv("C:/data/sample.csv")Sample Instructions
package::function(data, column_name1, column_name2) %>%
package::function() %>%
package::function()Actual Instructions
dplyr::distinct(df, species, type) %>%
dplyr::tally() %>%
dplyr::ungroup()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
df <- readr::read_csv("C:/data/sample.csv")Sample Instructions
package::function(data, column_name1, column_name2) %>%
package::function() %>%
package::function()Actual Instructions
dplyr::distinct(df, species, type) %>%
dplyr::tally() %>%
dplyr::ungroup() %>%
dplyr::arrange()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
df <- readr::read_csv("C:/data/sample.csv")Sample Instructions
package::function(data, column_name1, column_name2) %>%
package::function() %>%
package::function(function(n))Actual Instructions
dplyr::distinct(df, species, type) %>%
dplyr::tally() %>%
dplyr::ungroup() %>%
dplyr::arrange(desc(n))