View source: R/coalesce-data.R
coalesce_data | R Documentation |
Coalesce values in multiple columns by finding the first non-missing value at each position. Coalesced columns are removed.
coalesce_data(x, coalesce = list(), quiet = FALSE)
x |
A data frame. |
coalesce |
A uniquely named list of character vectors where the names are the new column names and the values are the names of the columns to coalesce. If a single value is provided for a column it is treated as a regular expression. |
quiet |
A flag specifying whether to provide messages. |
Coalescence is performed in the order specified in the coalesce argument such that a column produced by coalescence can be further coalesced.
The original data frame with one or more columns coalesced into a new column.
dplyr::coalesce()
data <- data.frame(x = c(1, NA, NA), y = c(NA, 3, NA), z = c(7, 8, 9), a = c(4, 5, 6))
coalesce_data(data, list(b = c("x", "y")), quiet = TRUE)
coalesce_data(data, list(z = c("y", "x"), d = c("z", "a")))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.