count_all: Count helper functions

Description Usage Arguments Value See Also Examples

View source: R/count.R

Description

Variants of dplyr's count function, letting you count the instances of each value in columns of your data frame.

count_all

group_by_all + tally

count_at

group_by_at + tally

count_if

group_by_if + tally

Usage

1
2
3
4
5
count_all(x, wt = NULL, sort = FALSE)

count_at(x, .vars, wt = NULL, sort = FALSE)

count_if(x, .predicate, wt = NULL, sort = FALSE)

Arguments

x

A tbl object.

wt

(Optional) If omitted (and no variable named n exists in the data), will count the number of rows. If specified, will perform a "weighted" tally by summing the (non-missing) values of variable wt. A column named n (but not nn or nnn) will be used as weighting variable by default in tally(), but not in count(). This argument is automatically quoted and later evaluated in the context of the data frame. It supports unquoting. Passed to count.

sort

Logical. Should the results be sorted by decreasing n.

.vars

A list of columns generated by vars(), a character vector of column names, a numeric vector of column positions, or NULL. Passed to group_by_at.

.predicate

A predicate function to be applied to the columns or a logical vector. The variables for which .predicate is or returns TRUE are selected. This argument is passed to rlang::as_function() and thus supports quosure-style lambda functions and strings representing function names. Passed to group_by_if.

Value

A summarized version of x.

See Also

count and group_by_all

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
library(dplyr)
n <- 100
quarks <- data_frame(
  first_gen = sample(c("up", "down"), n, replace = TRUE),
  second_gen = sample(c("charm", "strange"), n, replace = TRUE),
  third_gen = factor(sample(c("top", "bottom"), n, replace = TRUE))
)
quarks %>% count_all()
quarks %>% count_at(vars(contains("ir")))
quarks %>% count_if(is.factor)

richierocks/countess documentation built on June 30, 2018, 12:02 a.m.