na2miss function

Recode Data

Recode Data

Converts missing values (NAs) to or from a user specified value. From smwrBase package.

na2miss(x, to = -99999) miss2na(x, from = -99999)

Arguments

  • x: a vector. Missing values (NAs) are allowed.
  • to: the replacement value for NA.
  • from: the target value to match and replace with NA.

Returns

An object like x with each target value replaced by the specified value.

Note

The function na2miss converts missing values (NA) to the value to and is useful to prepare a vector for export and subsequent use by software external to R that does not handle NAs.

The function miss2na converts the value from to NA and can be used to recode data imported from external software that uses a special value to indicate missing values.

Examples

## Construct simple substitutions na2miss(c(1, 2, 3, NA, 5, 6))