cranvas (version 0.8.5)

var_names: Get variable names

Description

It is often flexible to input variables in plotting functions, and this generic function convert most common inputs (character, numeric or formula) to a character vector of variable names.

Usage

var_names(vars, data)
"var_names"(vars, data)
"var_names"(vars, data)
"var_names"(vars, data)
"var_names"(vars, data)

Arguments

vars
a character vector of variable names, or a numeric vector of column indices, or a two-sided formula like ~ x1 + x2 + x3
data
the data containing the variables

Value

A character vector

Details

Numeric indices are converted to character names according to the positions of variables in the data; all.vars is used to extract all variable names in a formula, and the special formula ~ . is treated differently: it means all variables in the data except thoese names starting with a dot (e.g. .color).

Examples

Run this code
var_names(~., mtcars)
var_names(~disp + hp, mtcars)
var_names(1:3, mtcars)

Run the code above in your browser using DataCamp Workspace