At the moment, when trying to select columns not directly by their name, but rather with grepl
, one has to add an additional call to the data.table
in the grepl
command using colnames()
. Is it possible to directly implement this functionality into data.table, so that one could use grepl
directly and the column names are automatically taken from the current data.table.
dt <- structure(list(Global.Company.Key = c(1380L, 1380L, 1380L, 1380L, 1380L)
, Calendar.Data.Year.and.Quarter = structure(c(2000, 2000, 2000, 2000, 2000), class = "yearqtr")
, Current.Assets.Total = c(2218, 2218, 2218, 2218, 2218)
, DRILL_TYPE = c("U", "D", "V", "H", "U")
, DI.Oil.Prod.Quarter = c(18395.6792379842, 1301949.24041659, 235.311086392291, 27261.8049684835, 4719.27956989249)
, DI.Gas.Prod.Quarter = c(1600471.27107983, 4882347.22928982, 2611.60215053765, 9634.76418242493, 27648.276603634)), .Names = c("Global.Company.Key", "Calendar.Data.Year.and.Quarter", "Current.Assets.Total", "DRILL_TYPE", "DI.Oil.Prod.Quarter", "DI.Gas.Prod.Quarter"), row.names = c(NA, -5L), class = c("data.table", "data.frame"), sorted = c("Global.Company.Key", "Calendar.Data.Year.and.Quarter"))
One example for a selection based with grepl:
dt[, grepl(glob2rx("Current.Assets*"), colnames(dt)), with = FALSE]
It would be nice, if something like this would be possible instead:
dt[, grepl(glob2rx("Current.Assets*")), with = FALSE]