case_by_index: Choose values row-wise from a set of columns according to an...

View source: R/case_by_index.R

case_by_indexR Documentation

Choose values row-wise from a set of columns according to an index column

Description

Adds a new column to the input data. The new column takes values row-wise from a supplied subset of columns in data. Which column's value is used for each row is determined by the corresponding integer in the column in the data given by index_column.

Usage

case_by_index(data, index_column, ..., into = "output")

Arguments

data

A data frame.

index_column

A column of integers indicating which column to select from for each row.

...

Columns to select values from. Passed to dplyr::select so can use tidy-select.

into

String giving the name of the new column.

Value

A data frame which matches the input data with a new column.

Examples

x <- tibble::tibble(a = 11:13, b = 21:23, index = c(1, 2, 1))
case_by_index(x, index, a, b, into = "new")

jedwards24/jemisc documentation built on Oct. 23, 2022, 10:17 p.m.