| find_var {sjmisc} | R Documentation | 
Find variable by name or label
Description
This functions finds variables in a data frame, which variable names or variable (and value) label attribute match a specific pattern. Regular expression for the pattern is supported.
Usage
find_var(
  data,
  pattern,
  ignore.case = TRUE,
  search = c("name_label", "name_value", "label_value", "name", "label", "value", "all"),
  out = c("table", "df", "index"),
  fuzzy = FALSE,
  regex = FALSE
)
find_in_data(
  data,
  pattern,
  ignore.case = TRUE,
  search = c("name_label", "name_value", "label_value", "name", "label", "value", "all"),
  out = c("table", "df", "index"),
  fuzzy = FALSE,
  regex = FALSE
)
Arguments
| data | A data frame. | 
| pattern | Character string to be matched in  | 
| ignore.case | Logical, whether matching should be case sensitive or not.
 | 
| search | Character string, indicating where  
 | 
| out | Output (return) format of the search results. May be abbreviated and must be one of: 
 | 
| fuzzy | Logical, if  | 
| regex | Logical, if  | 
Details
This function searches for pattern in data's column names
and - for labelled data - in all variable and value labels of data's
variables (see get_label for details on variable labels and
labelled data). Regular expressions are supported as well, by simply using
pattern = stringr::regex(...) or regex = TRUE.
Value
By default (i.e. out = "table", returns a data frame with three
columns: column number, variable name and variable label. If
out = "index", returns a named vector with column indices
of matching variables (variable names are used as names-attribute);
if out = "df", returns the matching variables as data frame
Examples
data(efc)
# find variables with "cop" in variable name
find_var(efc, "cop")
# return data frame with matching variables
find_var(efc, "cop", out = "df")
# or return column numbers
find_var(efc, "cop", out = "index")
# find variables with "dependency" in names and variable labels
library(sjlabelled)
find_var(efc, "dependency")
get_label(efc$e42dep)
# find variables with "level" in names and value labels
res <- find_var(efc, "level", search = "name_value", out = "df")
res
get_labels(res, attr.only = FALSE)
# use sjPlot::view_df() to view results
## Not run: 
library(sjPlot)
view_df(res)
## End(Not run)