data.table (version 1.9.6)

patterns: Regex patterns to extract columns from data.table

Description

From v1.9.6, melt.data.table has a new 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.

patterns is designed purely for convenience, to be used only within the measure.vars argument of melt.data.table. Column names corresponding to each pattern from the data.table is melted into a separate column.

Usage

patterns(...)

Arguments

...
A set of patterns. See example.

See Also

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

Examples

Run this code
# makes sense only in the context of melt at the moment
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"))

Run the code above in your browser using DataLab