Learn R Programming

plumbr (version 0.6.3)

ItemSelection-class: 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.

Arguments

Supported Selection Calculus

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

See Also

Selection for the rest of the details.

Examples

Run this code
## 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)

Run the code above in your browser using DataLab