I'm new to Leaflet and am wondering how it deals with missing values. Suppose I have a data frame with many columns, holding coordinates and other attributes. Ideally, if the addCircleMarkers
function comes upon a missing latitude or longitude value, it would skip it and not plot that row's coordinates. However, what I've been encountering it that if there's a single missing latitude/longitude value, no points at all will be drawn.
I can imagine going row by row in my data and checking for any NAs, and only plotting if there are none. But I feel like Leaflet would have a built-in way to deal with this. Does anyone know?
edit: Since somebody asked, here's my code for adding the markers (using the magrittr %>%
operator):
addCircleMarkers(~lon, ~lat, stroke=F,
fillOpacity = .6, color = coloring(), radius=radii) %>%
You could do something like, to test both lat and long columns
(df <- data.frame(a = c(1, NA, 4, NA), b = c(1, 2, 3, 5)))
a b
1 1 1
2 NA 2
3 4 3
4 NA 5
bools <- apply(cbind(complete.cases(df$a), complete.cases(df$b)), 1, all)
df[bools, ]
a b
1 1 1
3 4 3
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.