ItemSelection-class {plumbr}R Documentation

The ItemSelection class implements Selection for the very common case of selecting items in a dataset, optionally with weights.

Description

The ItemSelection class implements Selection for the very common case of selecting items in a dataset, optionally with weights.

Constructor

Interpreting the Selection

Any R object can represent the underlying selection, so for simplicity we recommend that the client interpret the selection through coercion. Each of these simply delegate to the underlying selection object, which will need to support all of them for consistency. The following coercions are supported, where x is a ItemSelection instance:

Supported Selection Calculus

All operations mentioned in Selection are supported: add, subtract, toggle, intersect.

Author(s)

Michael Lawrence

See Also

Selection for the rest of the details.

Examples

  ## Assume we have a dataset:
  data(Cars93, package="MASS")
  mf <- mutaframe(Cars93)
  mf$.color <- "gray"
  ## First step is to create a base selection
  sel <- ItemSelection()
  ## Now, link that selection to other cases in same dataset by some variable
  linked_sel <- sel$link(match_any_linker(Cars93["Manufacturer"]))
  ## Finally, scale that linked selection to the data
  linked_sel$scale(function(x, d) {
    d[as.logical(x), ".color"] <- "red"
  }, mf)
  ## To test, select some cases
  cases <- rep(FALSE, nrow(mf))
  cases[seq(1, 10, 2)] <- TRUE
  sel$replace(cases)

[Package plumbr version 0.6.10 Index]