sim_filter_keep_or_drop_some filters a melted similarity matrix to remove or keep specified rows.

sim_filter_keep_or_drop_some(
  sim_df,
  row_metadata,
  filter_keep = NULL,
  filter_drop = NULL,
  filter_side = NULL
)

Arguments

sim_df

data.frame with melted similarity matrix.

row_metadata

data.frame with row metadata.

filter_keep

optional data.frame of metadata specifying which rows to keep.

filter_drop

optional data.frame of metadata specifying which rows to drop.

filter_side

character string specifying which index to filter on. This must be one of the strings "left" or "right".

Value

Filtered sim_df as a data.frame, with some rows kept and some rows dropped. No filters applied if both filter_keep and filter_drop are NULL.

Examples

suppressMessages(suppressWarnings(library(magrittr)))
population <- tibble::tibble(
  Metadata_group = sample(c("a", "b"), 4, replace = TRUE),
  Metadata_type = sample(c("x", "y"), 4, replace = TRUE),
  x = rnorm(4),
  y = x + rnorm(4) / 100,
  z = y + rnorm(4) / 1000
)
annotation_cols <- c("Metadata_group", "Metadata_type")
sim_df <- matric::sim_calculate(population, method = "pearson")
row_metadata <- attr(sim_df, "row_metadata")
sim_df <- matric::sim_annotate(sim_df, row_metadata, annotation_cols)
filter_keep <- tibble::tibble(Metadata_group = "a", Metadata_type = "x")
filter_drop <- tibble::tibble(Metadata_group = "a", Metadata_type = "x")
matric::sim_filter_keep_or_drop_some(sim_df, row_metadata,
  filter_keep = filter_keep, filter_side = "left"
)
#>   id1 id2        sim Metadata_group1 Metadata_type1 Metadata_group2
#> 1   4   1 -0.7770026               a              x               b
#> 2   4   2  0.5608673               a              x               b
#> 3   4   3  0.7392556               a              x               a
#>   Metadata_type2
#> 1              x
#> 2              x
#> 3              y
matric::sim_filter_keep_or_drop_some(sim_df, row_metadata,
  filter_drop = filter_drop, filter_side = "left"
)
#>   id1 id2        sim Metadata_group1 Metadata_type1 Metadata_group2
#> 1   2   1 -0.9569599               b              x               b
#> 2   3   1 -0.9983228               a              y               b
#> 3   1   2 -0.9569599               b              x               b
#> 4   3   2  0.9721567               a              y               b
#> 5   1   3 -0.9983228               b              x               a
#> 6   2   3  0.9721567               b              x               a
#> 7   1   4 -0.7770026               b              x               a
#> 8   2   4  0.5608673               b              x               a
#> 9   3   4  0.7392556               a              y               a
#>   Metadata_type2
#> 1              x
#> 2              x
#> 3              x
#> 4              x
#> 5              y
#> 6              y
#> 7              x
#> 8              x
#> 9              x