parallelNonNA: Merge two Vectors selecting non-NA Values

View source: R/main.R

parallelNonNAR Documentation

Merge two Vectors selecting non-NA Values

Description

two vectors a and b of same length are merged in such a way that at index i the result vector contains (1) a[i] if a[i] is not NA and b[i] is NA or b[i] == a[i], (2) b[i] if b[i] is not NA and a[i] is NA or a[i] == b[i], (3) "" if a[i] is not NA and b[i] is not NA and a[i] != b[i] or if both a[i] and b[i] are NA

Usage

parallelNonNA(a, b)

Arguments

a

vector 1

b

vector 2

Value

character vector of same length as a and b

Examples

parallelNonNA(c(1, NA, 3), c(NA, 2, NA))  # "1" "2" "3"
  
parallelNonNA(c(1, NA, NA), c(NA, 2, NA)) # "1" "2" ""
  
## A warning is given if (non-NA) values at the same index differ
y <- parallelNonNA(c(1, 2, 3), c(1, 2, 4))
  
y # "1" "2" ""
  
## attribute "invalid" contains the index and values of the differing values
attr(y, "invalid")
  

KWB-R/kwb.utils documentation built on April 1, 2024, 7:12 a.m.