[Solved] Replace Values in a column wiht NA if values from another column are not 1 [closed]


Try

library(sp)
S@coords[,'roadtype'][S@coords[,'jointcount']!=1] <- NA
S
# SpatialPoints:
#     jointcount roadtype
#[1,]          1        3
#[2,]          4       NA
#[3,]          3       NA
#[4,]          1        1
#[5,]          1        4

data

jointcount = c(1,4,3,1,1)
roadtype = c(3,2,5,1,4)
S <- SpatialPoints(data.frame(jointcount,roadtype))

solved Replace Values in a column wiht NA if values from another column are not 1 [closed]