This function finds NAs (or defined missing values) in a vector, data.frame or matrix and returns a data.frame which contains two columns that includes the row number and column number of each NA.
A vector, data.frame or matrix which you want to pinpoint its NAs. (Mandatory)
A vector containing the value that should be concidered as missing value. The default is NA, but you can add to it or change it to your preference. See the example. (Optional)
This function provides a quick and easy way to locate and pinpoint NAs in a given vector, data.frame or matrix.
This function is also used in
inspect.na function of this package.
If a vector is given, the index of NAs will be returned in a numeric vector format. In case of a given matrix or data.frame the function will return a data.frame with two columns, one indicating the row number and one indicating the column number. Each row will represent a location of a NA.
In case no NA is found, the function will return NULL which makes it easy to use in if conditions using
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
## generate some variables # create a vector var1 <- 1:30 # add NA at random places var1[runif(7, 1, 30)] <- NA # pinpoint NAs pin.na(var1) # create a matrix var2 <- matrix(runif(100, 10, 99), nrow = 10) # add NA at random places var2[runif(9, 1, 100)] <- NA # pinpoint NAs pin.na(var2) ## define your own missing values: var2[runif(5, 1, 100)] <- "." pin.na(var2, na.value = c(NA, "."))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.