Not to be confused with a total row count of a dataframe (ie `nrow()`), this is a shortcut for `group_by_all()` followed by `count()`.
observation_count(data, desc = TRUE)
data | A dataframe or tibble. |
---|---|
desc | If TRUE, the output is arranged in descending order. Otherwise it is arranged in ascending order. |
Ungrouped dataframe with all input columns with the addition of an `n` column for the count.
group_by_all
,count
,group_by
,arrange
Other summary functions:
summarize_variables()
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) ) summarize_variables(data = test_data, incl_num_calc = FALSE)#> # A tibble: 4 x 7 #> Variable COUNT DISTINCT_COUNT NA_COUNT NA_STR_COUNT BLANK_COUNT #> <chr> <int> <int> <int> <int> <int> #> 1 A 10 3 4 0 0 #> 2 B 10 3 3 0 0 #> 3 C 10 7 1 0 0 #> 4 Group 10 2 0 0 0 #> # … with 1 more variable: DISTINCT_VALUES <chr>#> $SUMMARY #> # A tibble: 4 x 7 #> Variable COUNT DISTINCT_COUNT NA_COUNT NA_STR_COUNT BLANK_COUNT #> <chr> <int> <int> <int> <int> <int> #> 1 A 10 3 4 0 0 #> 2 B 10 3 3 0 0 #> 3 C 10 7 1 0 0 #> 4 Group 10 2 0 0 0 #> # … with 1 more variable: DISTINCT_VALUES <chr> #> #> $NUMERIC_CALCULATIONS #> # A tibble: 3 x 17 #> Variable MEAN MEAN_NA MEDIAN MEDIAN_NA SD SD_NA MAX MAX_NA MIN MIN_NA #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 A 1.33 NA 1 NA 0.516 NA 2 NA 1 NA #> 2 B 5.57 NA 6 NA 0.535 NA 6 NA 5 NA #> 3 C 6.05 NA 6.04 NA 0.0244 NA 6.09 NA 6.01 NA #> # … with 6 more variables: SUM <dbl>, SUM_NA <dbl>, DISTINCT_LENGTH <int>, #> # NA_LENGTH <int>, BLANK_LENGTH <int>, DISTINCT_STR <chr> #>#> $SUMMARY #> # A tibble: 6 x 8 #> # Groups: Group [2] #> Group Variable COUNT DISTINCT_COUNT NA_COUNT NA_STR_COUNT BLANK_COUNT #> <chr> <chr> <int> <int> <int> <int> <int> #> 1 Apple A 7 3 4 0 0 #> 2 Apple B 7 3 1 0 0 #> 3 Apple C 7 6 1 0 0 #> 4 Pear A 3 2 0 0 0 #> 5 Pear B 3 2 2 0 0 #> 6 Pear C 3 3 0 0 0 #> # … with 1 more variable: DISTINCT_VALUES <chr> #> #> $NUMERIC_CALCULATIONS #> # A tibble: 6 x 18 #> # Groups: Group [2] #> Group Variable MEAN MEAN_NA MEDIAN MEDIAN_NA SD SD_NA MAX MAX_NA #> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 Apple A 1.33 NA 1 NA 0.577 NA 2 NA #> 2 Apple B 5.5 NA 5.5 NA 0.548 NA 6 NA #> 3 Apple C 6.05 NA 6.04 NA 0.0293 NA 6.09 NA #> 4 Pear A 1.33 1.33 1 1 0.577 0.577 2 2 #> 5 Pear B 6 NA 6 NA NA NA 6 NA #> 6 Pear C 6.04 6.04 6.04 6.04 0.01 0.01 6.05 6.05 #> # … with 8 more variables: MIN <dbl>, MIN_NA <dbl>, SUM <dbl>, SUM_NA <dbl>, #> # DISTINCT_LENGTH <int>, NA_LENGTH <int>, BLANK_LENGTH <int>, #> # DISTINCT_STR <chr> #>#> # A tibble: 6 x 8 #> # Groups: Group [2] #> Group Variable COUNT DISTINCT_COUNT NA_COUNT NA_STR_COUNT BLANK_COUNT #> <chr> <chr> <int> <int> <int> <int> <int> #> 1 Apple A 7 3 4 0 0 #> 2 Apple B 7 3 1 0 0 #> 3 Apple C 7 6 1 0 0 #> 4 Pear A 3 2 0 0 0 #> 5 Pear B 3 2 2 0 0 #> 6 Pear C 3 3 0 0 0 #> # … with 1 more variable: DISTINCT_VALUES <chr>observation_count(data = test_data)#> # A tibble: 9 x 5 #> Group A B C n #> <chr> <int> <int> <dbl> <int> #> 1 Apple NA 5 6.04 2 #> 2 Apple 1 5 6.08 1 #> 3 Apple 1 NA 6.05 1 #> 4 Apple 2 6 6.01 1 #> 5 Apple NA 6 6.09 1 #> 6 Apple NA 6 NA 1 #> 7 Pear 1 NA 6.04 1 #> 8 Pear 1 NA 6.05 1 #> 9 Pear 2 6 6.03 1#> # A tibble: 15 x 3 #> Variable Value n #> <chr> <chr> <int> #> 1 Group Apple 7 #> 2 A 1 4 #> 3 A NA 4 #> 4 B 6 4 #> 5 B 5 3 #> 6 B NA 3 #> 7 C 6.04 3 #> 8 Group Pear 3 #> 9 A 2 2 #> 10 C 6.05 2 #> 11 C 6.01 1 #> 12 C 6.03 1 #> 13 C 6.08 1 #> 14 C 6.09 1 #> 15 C NA 1#> # A tibble: 19 x 4 #> Group Variable Value n #> <chr> <chr> <chr> <int> #> 1 Apple A NA 4 #> 2 Apple B 5 3 #> 3 Apple B 6 3 #> 4 Apple A 1 2 #> 5 Apple C 6.04 2 #> 6 Pear A 1 2 #> 7 Pear B NA 2 #> 8 Apple A 2 1 #> 9 Apple B NA 1 #> 10 Apple C 6.01 1 #> 11 Apple C 6.05 1 #> 12 Apple C 6.08 1 #> 13 Apple C 6.09 1 #> 14 Apple C NA 1 #> 15 Pear A 2 1 #> 16 Pear B 6 1 #> 17 Pear C 6.03 1 #> 18 Pear C 6.04 1 #> 19 Pear C 6.05 1