patterns returns the matching indices in the argument
corresponding to the regular expression patterns provided. The patterns must be
melt.data.table has an enhanced functionality
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.
A set of regular expression patterns.
A character vector of names to which each pattern is matched.
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 implicitly assumed to be names of input # data.table, if not provided. melt(DT, measure.vars = patterns("^x", "^y"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.