Get paired entities from a data frame based on the other column
mutate-helper-2.Rd
Get paired entities from a data frame based on the other column
Arguments
- df
The data frame.
- id
The column name in
df
for the ids to be returned in the final output- compare
The column name in
df
to compare the values for each id inid
.- idents
The values in
compare
to compare. It could be either an an integer or a vector. If it is an integer, the number of values incompare
must be the same as the integer for theid
to be regarded as paired. If it is a vector, the values incompare
must be the same as the values inidents
for theid
to be regarded as paired.- uniq
Whether to return unique ids or not. Default is
TRUE
. IfFALSE
, you can mutate the meta data frame with the returned ids. Non-paired ids will beNA
.
Examples
df <- data.frame(
id = c("A", "A", "B", "B", "C", "C", "D", "D"),
compare = c(1, 2, 1, 1, 1, 2, 1, 2)
)
paired(df, id, compare, 2)
#> [1] "A" "B" "C" "D"
paired(df, id, compare, c(1, 2))
#> [1] "A" "C" "D"
paired(df, id, compare, c(1, 2), uniq = FALSE)
#> [1] "A" "A" NA NA "C" "C" "D" "D"