Skip to contents

Index columns by attribute name & value

Usage

index_col_by_attr(x, name, value, exact = TRUE)

Arguments

x

tabular data.

name

Character: Name of attribute.

value

Character: Value of attribute.

exact

Logical: Passed to attr when retrieving attribute value. If TRUE, attribute name must match name exactly, otherwise, partial match is allowed.

Value

Integer vector.

Author

EDG

Examples

library(data.table)
x <- data.table(
  id = 1:5,
  sbp = rnorm(5, 120, 15),
  dbp = rnorm(5, 80, 10),
  paO2 = rnorm(5, 90, 10),
  paCO2 = rnorm(5, 40, 5)
)
setattr(x[["sbp"]], "source", "outpatient")
setattr(x[["dbp"]], "source", "outpatient")
setattr(x[["paO2"]], "source", "icu")
setattr(x[["paCO2"]], "source", "icu")
index_col_by_attr(x, "source", "icu")
#>  paO2 paCO2 
#>     4     5