column_find | R Documentation |
Identifies or extracts columns in a dataframe using a string.
column_find(pattern, data, return = "logical", invert = FALSE, antipattern)
pattern |
a character string that is used to find the columns of interest. It can be a regular expression. |
data |
a data frame. |
return |
a string specifying the output desired. "logical" (the default) returns a logical vector with TRUE indicating that a column name includes the pattern. "numeric" returns a numeric vector that identifies the column numbers matching the pattern. "character" returns a character vector with the column names that match the pattern. "data.frame" returns a data frame that includes only those columns whose names match the pattern. |
invert |
if TRUE, identifies or extracts columns that DO NOT match the pattern. |
antipattern |
an optional character string that is used to identify columns that should not be returned. It can be a regular expression. |
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_find(pattern = "x", data = x, return = "logical")
column_find(pattern = "x", data = x, return = "numeric")
column_find(pattern = "x", data = x, return = "character")
column_find(pattern = "x", data = x, return = "data.frame")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.