Combine data across columns
Combine data across columns. If NA is the only value across all focal columns for given row(s), NA will be returned for those row(s).
combine_data_across_cols(data = NULL, cols = NULL)
data
: a data object (a data frame or a data.table)cols
: a character vector containing names of columns, across which to combine datathe output will be a numeric or character vector.
dt <- data.frame(v1 = c(1, NA), v2 = c(NA, 2)) dt combine_data_across_cols(data = dt, cols = c("v1", "v2")) dt <- data.frame(v1 = c(1, 2, NA), v2 = c(NA, 4, 3)) dt combine_data_across_cols(data = dt, cols = c("v1", "v2")) dt <- data.frame(v1 = c(1, NA, NA), v2 = c(NA, 2, NA)) dt combine_data_across_cols(data = dt, cols = c("v1", "v2"))
Useful links