Learn R Programming

spatialEco (version 0.1-2)

sp.na.omit: sp na.omit

Description

Removes row or column NA's in sp object

Usage

sp.na.omit(x, margin = 1)

Arguments

x
Object of class SpatialPointsDataFrame OR SpatialPolygonsDataFrame
margin
Margin (1,2) of data.frame 1 for rows or 2 for columns

Examples

Run this code
require(sp)
  data(meuse)
    coordinates(meuse) <- ~x+y

   # Display rows with NA
   meuse@data[!complete.cases(meuse@data),]

   # Remove 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 columns with NA's
   meuse2 <- sp.na.omit(meuse, margin=2)
     head(meuse@data)
       head(meuse2@data)

Run the code above in your browser using DataLab