Summarizes each column with max value
summarize_max(data, ..., na.rm = TRUE, grouper)
data | A dataframe or tibble. |
---|---|
... | (Optional) Numeric columns to summarize. |
na.rm | TRUE if true NA are to be removed. |
grouper | (Optional) Group by column. |
Other summarize functions:
value_count()
library(tidyverse) test_data <- tibble( Group = sample(c("Apple", "Pear"), size = 10, replace = TRUE), A = sample(c(NA_integer_, 1:3), size = 10, replace = TRUE), B = sample(c(NA_integer_, 4:6), size = 10, replace = TRUE), C = sample(c(NA_real_, seq(from = 6.01, to = 6.09, by = 0.01)), size = 10, replace = TRUE) ) # Checking that all numeric cols are captured all_numeric_cols(data = test_data)#> [1] "A" "B" "C"# Ungrouped Summary summarize_max(test_data)#> # A tibble: 1 x 3 #> A B C #> <int> <int> <dbl> #> 1 3 5 6.09summarize_max(test_data, A)#> # A tibble: 1 x 1 #> A #> <int> #> 1 3# Grouped Summary summarize_max(test_data, grouper = Group)#> # A tibble: 2 x 4 #> Group A B C #> <chr> <int> <int> <dbl> #> 1 Apple 3 4 6.09 #> 2 Pear 3 5 6.09summarize_max(test_data, B, na.rm = TRUE, grouper = Group)#> # A tibble: 2 x 2 #> Group B #> <chr> <int> #> 1 Apple 4 #> 2 Pear 5summarize_max(test_data, B, na.rm = FALSE, grouper = Group)#> # A tibble: 2 x 2 #> Group B #> <chr> <int> #> 1 Apple NA #> 2 Pear NA