Skip to contents

Subsets rows and columns like an ordinary tibble, but the class travels only while the result still satisfies the contract: id1/id2 (both character) and dissim (numeric) all present. Dropping any of them leaves something that can no longer be described as a pairwise distance table, and the result is a plain tibble, without an error.

Usage

# S3 method for class 'pairwise_distances'
x[...]

Arguments

x

A pairwise_distances object.

...

Passed on to the tibble/data frame method.

Value

The subset: still a pairwise_distances (or its tale_distances/domain_distances subclass) if the contract holds, otherwise a plain tibble.

Details

Squareness is not checked here (see distances_assert_square): subsetting rows is an everyday way to end up with a non-square table.

Examples

d <- pairwise_distances(data.frame(
  id1 = c("A1", "A1", "A2", "A2"),
  id2 = c("A1", "A2", "A1", "A2"),
  dissim = c(0, 35, 35, 0)
))
is_pairwise_distances(d[1:2, ]) # row subsetting never breaks the contract
#> [1] TRUE
class(d[, "id1"])               # dropping dissim/id2: the class steps aside
#> [1] "tbl_df"     "tbl"        "data.frame"