R/na_null_Function.R

Defines functions null.if.cb null.if na.if

na.if <- function(x, value = NULL, replacement, na = T) {
  if (na == T) {
    x[is.na(x)] <- replacement
  } else if (na == F) {
    x[x %in% value] <- replacement
  }
  x
}

null.if <- function(x, replacement = NA) {
  x <- ifelse(is.null(x) | x %in% c("", " ", 'NULL', 'null'), replacement, x)
  if (length(x) == 0) {
    x <- replacement
  }
  x
}


null.if.cb <- function(x, replacement = NA) {
  x <- ifelse(is.null(x) | x %in% c("", " ", "NULL", 'null', '{ND}', 'ND', '{OB}', 'OB', -999997, -999999), replacement, x)
  if (length(x) == 0) {
    x <- replacement
  }
  x
}
Ehsan-F/R-Mixtape documentation built on June 24, 2020, 12:22 a.m.