Skip to contents

List column names by attribute

Usage

dt_names_by_attr(x, attribute, exact = TRUE, sorted = TRUE)

Arguments

x

data.table: Input data.table.

attribute

Character: name of attribute.

exact

Logical: If TRUE, use exact matching.

sorted

Logical: If TRUE, sort the output.

Value

Character 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[["id"]], "source", "demographics")
setattr(x[["sbp"]], "source", "outpatient")
setattr(x[["dbp"]], "source", "outpatient")
setattr(x[["paO2"]], "source", "icu")
setattr(x[["paCO2"]], "source", "icu")

dt_names_by_attr(x, "source", "outpatient")
#> $demographics
#> [1] "id"
#> 
#> $outpatient
#> [1] "dbp" "sbp"
#> 
#> $icu
#> [1] "paCO2" "paO2" 
#>