remove_group_subsets: Remove groups of rows within a data.frame that are proper...

Description Usage Arguments Value Examples

View source: R/remove_group_subsets.R

Description

Remove groups of rows within a data.frame that are proper subsets of other defined groups, to limit group duplication

Usage

1
remove_group_subsets(x, target = NULL, group, by, invert = FALSE)

Arguments

x

Focal data.frame containing one or more defined groups

target

Optional target data.frame containing one or more defined groups. Defaults to NULL, in which case the target is x itself.

group

Name of the column within x (and target, if applicable) defining groups

by

Character vector giving the column(s) by which x and target should be matched and compared.

invert

Logical indicating whether to invert the results, and thus retain groups that are subsets rather than removing them.

Value

The focal data.frame x, excluding groups representing subsets of other groups.

Examples

1
2
3
4
5
6
7
8
x <- data.frame(
  x1 = c("a", "a", "a",  "b", "b",  "a", "a",  "b", "c",  "c", "b"),
  x2 = c("a", "a", "a",  "b", "b",  "a", "a",  "b", "c",  "c", "b"),
  g =  c("1", "1", "1",  "2", "2",  "3", "3",  "4", "4",  "5", "5"),
  stringsAsFactors = FALSE
)

remove_group_subsets(x, group = "g", by = c("x1", "x2"))

epicentre-msf/llutils documentation built on Nov. 9, 2020, 8:24 p.m.