replaceNAs: Replaces missing variables in a vector as '<NA>'.

Description Usage Arguments Details Value Author(s) Examples

View source: R/utilar.R

Description

Given a vector (numeric, character, double, factor) with missingness coded as not NA, replace it as NA. Some examples are - 9 N/A Unknown, Not Available etc.

Usage

1
replaceNAs(x, vNA)

Arguments

x

A vector of values - numeric, character, double or factor.

vNA

A character vector of values to be replaced that are coded as missing into NA

Details

Both arguments should be supplied. If typeof is not matched to one of the following - character, double, integer or factor, a character vector is returned

Value

x.na

A vector with misisng values coded as NA. If typeof did not match the following - character, double, integer or factor, a character vector is returned

Author(s)

Arshi Arora

Examples

1
2
3
4
5
6
7
8
  set.seed(123)
  #sample 20 numbers from 1 -10, say we want to replace the 9s to NA
  x<-sample(1:10, 20, replace=TRUE)
  #x
  #[1]  3  8  5  9 10  1  6  9  6  5 10  5  7  6  2  9  3  1  4 10

  x.na<-replaceNAs(x,9)
  #[1]  3  8  5 NA 10  1  6 NA  6  5 10  5  7  6  2 NA  3  1  4 10

arorarshi/utilar documentation built on July 6, 2020, 8:29 a.m.