which_cols: Give DT ready column numbers from names or numbers

which_colsR Documentation

Give DT ready column numbers from names or numbers

Description

Given a vector of column names or numbers, return the corresponding column indices.

Usage

which_cols(x, .data)

Arguments

x

(character/numeric) Column numbers or names to be converted to column indices.

.data

(data.frame) The data frame from which column names are extracted. This parameter is used only in the character method.

Value

numeric A vector of column indices.

Examples

df <- data.frame(A = 1:3, B = 4:6, C = 7:9)
which_cols(c("A", "B"), df)  # Returns: 1 2
which_cols(c(1, 3), df)      # Returns: 1 3

COHHIO/RminorElevated documentation built on Nov. 14, 2024, 6:28 p.m.