View source: R/case_by_index.R
case_by_index | R Documentation |
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
.
case_by_index(data, index_column, ..., into = "output")
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 |
into |
String giving the name of the new column. |
A data frame which matches the input data
with a new column.
x <- tibble::tibble(a = 11:13, b = 21:23, index = c(1, 2, 1)) case_by_index(x, index, a, b, into = "new")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.