pairwise_count: Count pairs of items within a group

View source: R/pairwise_count.R

pairwise_countR Documentation

Count pairs of items within a group

Description

Count the number of times each pair of items appear together within a group defined by "feature." For example, this could count the number of times two words appear within documents).

Usage

pairwise_count(tbl, item, feature, sort = FALSE, diag = FALSE, upper = TRUE)

Arguments

tbl

Table

item

Item to count pairs of; will end up in item1 and item2 columns

feature

Column within which to count pairs item2 columns

sort

Sort the output by n?

diag

Count.

upper

Remove duplicates.

Examples

## Not run: 
library(dplyr)
dat <- tibble(group = rep(1:5, each = 2),
              letter = c("a", "b",
                         "a", "c",
                         "a", "c",
                         "b", "e",
                         "b", "f"))

# count the number of times two letters appear together
count_pairwise(dat, letter, group)
count_pairwise(dat, letter, group, sort = TRUE)
count_pairwise(dat, letter, group, sort = TRUE, diag = TRUE)

## End(Not run)


Kudusch/ktools documentation built on Oct. 30, 2022, 10:13 p.m.