balt_orig <- read.shape(system.file("shapes/baltim.shp", package="maptools")[1])
plot(balt_orig)
balt_df <- balt_orig$att.data
balt_cheap <- balt_df[balt_df$PRICE < 40,]
file <- tempfile("")
write.pointShape(balt_cheap, file, coordinates=cbind(balt_cheap$X, balt_cheap$Y))
getinfo.shape(paste(file, ".shp", sep=""))
balt_new <- read.shape(paste(file, ".shp", sep=""))
plot(balt_new, fg="red", glyph=1, add=TRUE)
Run the code above in your browser using DataLab