Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

sp.na.omit

sp na.omit


Description

Removes row or column NA's in sp object

Usage

sp.na.omit(x, col.name = NULL, margin = 1)

Arguments

x

Object of class SpatialPointsDataFrame OR SpatialPolygonsDataFrame

col.name

The name of a specific column to remove NA's from

margin

Margin (1,2) of data.frame 1 for rows or 2 for columns

Note

This function will remove all NA's in the object or NA's associated with a specific column.

Author(s)

Jeffrey S. Evans <jeffrey_evans<at>tnc.org>

Examples

library(sp)
 data(meuse)
 coordinates(meuse) <- ~x+y
   
 # Display rows with NA  
 meuse@data[!complete.cases(meuse@data),] 

 # Remove all NA's in rows (and associated points)
 meuse2 <- sp.na.omit(meuse) 
   dim(meuse)
   dim(meuse2)
   
 # Plot deleted points in red
 plot(meuse, col='red', pch=20)
 plot(meuse2, col='black', pch=20, add=TRUE)

 # Remove NA's associated with specific column 
 meuse2 <- sp.na.omit(meuse, col.name = "om") 
   head(meuse@data)
   head(meuse2@data)

spatialEco

Spatial Analysis and Modelling Utilities

v1.3-6
GPL-3
Authors
Jeffrey S. Evans [aut, cre], Melanie A. Murphy [ctb], Karthik Ram [ctb]
Initial release
2021-03-24

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.