Extracting variable name as string in a Spatial Polygons Data Frame

91 views Asked by At

I need to write a function that omits NA values from a Spatial Polygons Data Frame, but only for a single column. I am currently using

sp.na.omit(col.name= )

The issue is that the input in the function is of the format

spatialdf$variable

and to work the function needs the variable name as a string, i.e. "variable". I cannot seem to find a way to extrapolate variable out of spatialdf$variable.

select() from dplyr does not work because it is a SpatialPolygonsDataFrame.

Minimal Reproducible Example:

library(sp)
library(spatialEco)
data(meuse)
coordinates(meuse) = ~x+y

myfunction <- function (data, variable){
  data <- sp.na.omit(data, col.name = variable)
}

myfunction(meuse, "zinc")

My issue is that for the function that I am currently using, "zinc" has to be entered as meuse$zinc in all other instances, but for this specific instance i need it to be as a string.

How do I take meuse$zinc and get "zinc"?

I would greatly appreciate any help

0

There are 0 answers