Learn R Programming

kim (version 0.6.1)

combine_data_across_cols: Combine data across columns

Description

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).

Usage

combine_data_across_cols(data = NULL, cols = NULL)

Value

the output will be a numeric or character vector.

Arguments

data

a data object (a data frame or a data.table)

cols

a character vector containing names of columns, across which to combine data

Examples

Run this code
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"))

Run the code above in your browser using DataLab