patterns

0th

Percentile

Obtain matching indices corresponding to patterns

patterns returns the matching indices in the argument cols corresponding to the regular expression patterns provided. The patterns must be supported by grep.

From v1.9.6, melt.data.table has an enhanced functionality in which measure.vars argument can accept a list of column names and melt them into separate columns. See the Efficient reshaping using data.tables vignette linked below to learn more.

Keywords
data
Usage
patterns(..., cols=character(0))
Arguments
...

A set of regular expression patterns.

cols

A character vector of names to which each pattern is matched.

See Also

melt, https://github.com/Rdatatable/data.table/wiki/Getting-started

Aliases
  • patterns
Examples
# NOT RUN {
DT = data.table(x1 = 1:5, x2 = 6:10, y1 = letters[1:5], y2 = letters[6:10])
# melt all columns that begin with 'x' & 'y', respectively, into separate columns
melt(DT, measure.vars = patterns("^x", "^y", cols=names(DT)))
# when used with melt, 'cols' is implictly assumed to be names of input
# data.table, if not provided.
melt(DT, measure.vars = patterns("^x", "^y"))
# }
Documentation reproduced from package data.table, version 1.11.8, License: MPL-2.0 | file LICENSE

Community examples

Looks like there are no examples yet.