Question:
I have a sf-object in R and want to select a few polygons according to their location name. I would like to apply the dpylr approach using the filter function (analog to this example). However, this does not work and returns an error message.
Is this a bug, is there a problem with the data, or is something wrong with the code?
Example:
> wards %>%
+ filter(NAME_WARD == "Bumbuta")
Error in data.matrix(data) :
(list) object cannot be coerced to type 'double'
In addition: Warning messages:
1: In data.matrix(data) : NAs introduced by coercion
2: In data.matrix(data) : NAs introduced by coercion
3: In data.matrix(data) : NAs introduced by coercion
Data:
> wards
Simple feature collection with 5 features and 6 fields
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: 35.82647 ymin: -4.968201 xmax: 36.3376 ymax: -4.55612
epsg (SRID): 4326
proj4string: +proj=longlat +datum=WGS84 +no_defs
NAME_REG NAME_DIST NAME_WARD ID_REG ID_DIST ID_WARD geometry
1 Dodoma Kondoa Bumbuta 01 0101 0101011 MULTIPOLYGON (((35.93715495...
2 Dodoma Kondoa Pahi 01 0101 0101021 MULTIPOLYGON (((35.93456275...
3 Dodoma Kondoa Haubi 01 0101 0101041 MULTIPOLYGON (((35.92014452...
4 Dodoma Kondoa Kalamba 01 0101 0101051 MULTIPOLYGON (((35.88398049...
5 Dodoma Kondoa Kwadelo 01 0101 0101061 MULTIPOLYGON (((36.33663165...
> str(wards)
Classes ‘sf’ and 'data.frame': 5 obs. of 7 variables:
$ NAME_REG : chr "Dodoma" "Dodoma" "Dodoma" "Dodoma" ...
$ NAME_DIST: chr "Kondoa" "Kondoa" "Kondoa" "Kondoa" ...
$ NAME_WARD: chr "Bumbuta" "Pahi" "Haubi" "Kalamba" ...
$ ID_REG : chr "01" "01" "01" "01" ...
$ ID_DIST : chr "0101" "0101" "0101" "0101" ...
$ ID_WARD : chr "0101011" "0101021" "0101041" "0101051" ...
$ geometry :sfc_MULTIPOLYGON of length 5; first list element: List of 1
..$ :List of 1
.. ..$ : num [1:200, 1:2] 35.9 35.9 35.9 35.9 35.9 ...
..- attr(*, "class")= chr "XY" "MULTIPOLYGON" "sfg"
- attr(*, "sf_column")= chr "geometry"
- attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA
..- attr(*, "names")= chr "NAME_REG" "NAME_DIST" "NAME_WARD" "ID_REG" ...