i2index: Input parameter check for subsetting operations

Description Usage Arguments Value Author(s) Examples

View source: R/i2index.R

Description

i2index is a simple helper function to be used in subsetting functions. It checks and converts the parameter i, which can be of type integer, logical or character to integer vector that can be used as index for subsetting.

Usage

1

Arguments

i

character logical or integer used in [i] for subsetting.

length

integer representing the length of the object to be subsetted.

names

character with the names (rownames or similar) of the object. This is only required if i is of type character.

Value

integer with the indices

Author(s)

Johannes Rainer

Examples

1
2
3
4
5
6
7
8
## With `i` being an `integer`
i2index(c(4, 1, 3), length = 10)

## With `i` being a `logical`
i2index(c(TRUE, FALSE, FALSE, TRUE, FALSE), length = 5)

## With `i` being a `character`
i2index(c("b", "a", "d"), length = 5, names = c("a", "b", "c", "d", "e"))

MsCoreUtils documentation built on Nov. 8, 2020, 10:59 p.m.