swap_na: Replace NAs

Description Usage Arguments Examples

View source: R/swap_na.R

Description

This function swaps out NA values in an object (vector, matrix - call with lapply for lists) while retaining dimensions and names. If no NA values are found, the object is returned as is.

Usage

1
swap_na(possNAs, swap = 0)

Arguments

possNAs

An R object that may or may not contain NA values.

swap

The value to swap NA for. Defaults to 0. Changing to a character value after inputting only numerical values will change ALL numbers to characters if using a matrix.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
test.matrix <- matrix(data = c(1, 2, 3, NA, 4, 6), nrow = 2)
test.matrix
     [,1] [,2] [,3]
[1,]    1    3    4
[2,]    2   NA    6

swap_na(test.matrix, swap = 0)
     [,1] [,2] [,3]
[1,]    1    3    4
[2,]    2    0    6

danjamesadams/Dantools documentation built on Aug. 24, 2019, 6:15 p.m.