View source: R/column_combine.R
column_combine | R Documentation |
Creates a composite column using only columns in a data frame that have names that match a pattern.
column_combine(
pattern,
data,
fun = mean,
verbose = FALSE,
message = TRUE,
invert = FALSE
)
pattern |
a character string that is used to find the columns of interest. It can be a regular expression. |
data |
a data frame. |
fun |
the function to use to create the composite column; defaults to 'mean'. |
verbose |
specifies whether all column names should be listed, regardless of length. |
message |
if TRUE, messages are generated telling the user which columns were used to create the composite. |
invert |
if TRUE, combines columns that DO NOT match the pattern. |
x <- data.frame(my_column_x = 1:10,
my_column_x2 = 1:10 * rnorm(10, mean = 1),
my_column_x3 = 1:10 * rnorm(10, mean = 1),
my_column_y = 11:20,
my_column_y2 = 11:20 * rnorm(10, mean = 1),
my_column_y3 = 11:20 * rnorm(10, mean = 1))
column_combine(pattern = "x", data = x)
column_combine(pattern = "_y", data = x)
column_combine(pattern = "my_column", data = x)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.