remove.na: Remove and Count NAs

Description Usage Arguments Details Value Note Author(s) See Also Examples

Description

Function to remove rows containing NAs from a data vector or matrix. Also counts the number of rows remaining, the number of rows deleted, and in the case of a matrix the number of columns. The results are returned in a list for subsequent processing in the calling function.

Usage

1
remove.na(xx, iftell = TRUE)

Arguments

xx

name of the vector or matrix to be processed.

iftell

if iftell = TRUE, the default, the number of removed records is displayed.

Details

This function is called by many of the procedures in the ‘rgr’ package. If one or more NAs are found the user is informed of how many. In general a data frame will have been cleared of any <values represented by negative values or zeros prior to executing the procedure calling this function, see ltdl.fix.df, or ltdl.fix if a single vector is being processed.

Value

x

a data vector or matrix containing the elements in the vector or rows of the matrix xx without NAs.

n

the length of x.

m

the number of columns in the matrix xx, if xx is a vector the value 1 is returned.

nna

the number of rows removed from xx.

Note

The iftell ‘switch’ is used to suppress the display of the NA count in some summary statistics tables as the information is included in the table.

Author(s)

Robert G. Garrett

See Also

ltdl.fix.df, where.na

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
## remove NAs
xx <- c(15, 39, 18, 16, NA, 53)
temp.x <- remove.na(xx)
x <- temp.x$x[1:temp.x$n]

## to recover the other values returned
n <- temp.x$n
m <- temp.x$m
nna <- temp.x$nna

## to remove NA replacing a -9999 in kola.o
data(kola.o)
kola.o.fixed <- ltdl.fix.df(kola.o, coded = -9999)
temp.x <- remove.na(kola.o.fixed$pH)
x <- temp.x$x[1:temp.x$n]

## Clean-up
rm(xx)
rm(temp.x)
rm(x)
rm(n)
rm(m)
rm(nna)
rm(kola.o.fixed)

Example output

Loading required package: MASS
Loading required package: fastICA

  1 NA(s) removed from vector
  n = 617 by p = 44 matrix checked, 0 NA(s) present
  0 factor variable(s) present
  2 value(s) coded -9999 set to NA
  0 -ve value(s) set to +ve half the negative value

  1 NA(s) removed from vector

rgr documentation built on May 2, 2019, 6:09 a.m.

Related to remove.na in rgr...