where.na: Identify Vector Elements or Data Frame/Matrix Rows with NAs

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

Description

Function to display the positions of elements in a vector containing NAs, or the numbers of rows in a data frame or matrix containing one or more NAs. The function can also be used to remove NAs.

Usage

1

Arguments

x

name of the vector or matrix/data frame to be processed.

Value

whichna

a vector containing the indices of the positions in x containing NAs.

Note

This function is based on the S-Plus function which.na and is useful in finding the location of NAs in a data set. While remove.na removes NAs it does not identify their positions. A vector is returned that can be used to remove NAs, see example below.

Remember, a matrix is also a vector with the columns occurring sequentially.

Author(s)

S-Plus team and Robert G. Garrett

See Also

remove.na

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## Identify rows with NAs
xx <- c(15, 39, 18, 16, NA, 53)
where.na(xx)

## To use where.na to remove NAs, method 1
xx
temp <- where.na(xx)
temp
xxx <- xx[-temp]
xxx

## To use where.na to remove NAs, method 2
xx
xxx <- xx[-where.na(xx)]
xxx

## Clean-up
rm(xx)
rm(xxx)
rm(temp)

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

Related to where.na in rgr...