pairwise_count_dt | R Documentation |
Count the number of times each pair
of items appear together within a group.
For example, this could count the number of times two words appear within documents.
This function has referred to pairwise_count
in widyr package,
but with very different defaults on several parameters.
pairwise_count_dt(
.data,
.group,
.value,
upper = FALSE,
diag = FALSE,
sort = TRUE
)
.data |
A data.frame. |
.group |
Column name of counting group. |
.value |
Item to count pairs, will end up in |
upper |
When |
diag |
Whether to include diagonal (V1==V2) in output. Default uses |
sort |
Whether to sort rows by counts. Default uses |
A data.table with 3 columns (named as "V1","V2" and "n"), containing combinations in "V1" and "V2", and counts in "n".
pairwise_count
dat <- data.table(group = rep(1:5, each = 2),
letter = c("a", "b",
"a", "c",
"a", "c",
"b", "e",
"b", "f"))
pairwise_count_dt(dat,group,letter)
pairwise_count_dt(dat,group,letter,sort = FALSE)
pairwise_count_dt(dat,group,letter,upper = TRUE)
pairwise_count_dt(dat,group,letter,diag = TRUE)
pairwise_count_dt(dat,group,letter,diag = TRUE,upper = TRUE)
# The column name could be specified using character.
pairwise_count_dt(dat,"group","letter")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.