Generate column indices

colspec(x, cols = NULL)

Arguments

x

a data frame

cols

a column specification

Value

A vector of integers

Details

cols can be a logical, numeric, or character vector indicating which columns to extract. Or cols can be a formula with the right-hand-side variable specifying the columns. This function is used where ever a cols option is present throughout kdtools.

Examples

colspec(mtcars, c(1, 3, 6))
#> [1] 1 3 6
colspec(mtcars, c("mpg", "disp", "wt"))
#> [1] 1 3 6
colspec(mtcars, ~mpg + disp + wt)
#> [1] 1 3 6
colspec(mtcars, c(TRUE, FALSE, TRUE, FALSE, FALSE, TRUE,
                  FALSE, FALSE, FALSE, FALSE, FALSE))
#> [1] 1 3 6