ms_filter_fields {rmapshaper} | R Documentation |
Delete fields in the attribute table
Description
Removes all fields except those listed in the fields
parameter
Usage
ms_filter_fields(input, fields, ...)
Arguments
input |
spatial object to filter fields on. One of:
|
fields |
character vector of fields to retain. |
... |
Arguments passed on to
|
Value
object with only specified attributes retained, in the same class as the input
Examples
library(geojsonsf)
library(sf)
poly <- structure("{\"type\":\"FeatureCollection\",
\"features\":[{\"type\":\"Feature\",
\"properties\":{\"a\": 1, \"b\":2, \"c\": 3},
\"geometry\":{\"type\":\"Polygon\",
\"coordinates\":[[[102,2],[102,4],[104,4],[104,2],[102,2]]]}}]}",
class = c("geojson", "json"))
poly <- geojson_sf(poly)
poly
# Filter (keep) fields a and b, drop c
out <- ms_filter_fields(poly, c("a", "b"))
out