Learn R Programming

rgr (version 1.0.4)

remove.na: Remove and Count NAs

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

remove.na(xx)

Arguments

xx
name of the vector or matrix to be processed.

Value

  • xa data vector or matrix containing the rows of xx without NAs.
  • nthe length of x.
  • mthe number of columns in the matrix xx, if xx is a vector the value 1 is returned.
  • nnathe number of rows removed from xx.

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 dataframe will have been cleared of any ltdl.fix.df, or ltdl.fix if a single vector is being processed.

See Also

ltdl.fix.df

Examples

Run this code
## 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]

Run the code above in your browser using DataLab