I have a shape file that I have read into R. It is a US Census shape file
that has a code for each school district in a state.
I now want to create a vector of the districts that are not customers and
plot them.
library(maptools)
library(maps)
elem_school_district <- readShapePoly("E:/My Documents/Web
Usage/RTest/School_District_Shape_Files/Elementary School
Districts/unzipped/tl_2010_47_elsd10.shp", IDvar="NAME10",
proj4string=CRS("+pro=11 + ellps=clrk66"))
secondary_school_district <- readShapePoly("E:/My Documents/Web
Usage/RTest/School_District_Shape_Files/Secondary School
Districts/unzipped/tl_2010_47_scsd10.shp", IDvar="NAME10",
proj4string=CRS("+proj=ll + ellps=clrk66"))
unified_school_district <- readShapePoly("E:/My Documents/Web
Usage/RTest/School_District_Shape_Files/Unified_School_Districts/Unzipped/tl_2010_47_unsd10.shp",
IDvar="NAME10", proj4string=CRS("+proj=ll + ellps=clrk66"))
plot(elem_school_district, col="green")
plot(secondary_school_district, col="blue", add=TRUE)
plot(unified_school_district, col="red", add=TRUE)
i=1
counter=1
schools_not_customers <- c("4700570", "470090",
"4701590", "4700570")
for (counter in length(schools_not_customers)) {
for (i in length(unified_school_district)) {
if (unified_school_district$GEOID10 == schools_not_customers[counter]){
color_white_districts<-unified_school_district[i,]
}
}
counter=counter+1
}
plot(color_white_districts, col="white", add=TRUE)
The above does not work can someone point me in the right direction?
I would appreciate it. Thanks in advance.
--
View this message in context:
http://r.789695.n4.nabble.com/Comparing-to-create-a-new-list-tp4633856.html
Sent from the R help mailing list archive at Nabble.com.
So I got this to work and thought that I should post it, in case it might
help someone else:
library(maptools)
library(maps)
elem_school_district <- readShapePoly("E:/My Documents/Web
Usage/RTest/School_District_Shape_Files/Elementary School
Districts/unzipped/tl_2010_47_elsd10.shp", IDvar="NAME10",
proj4string=CRS("+pro=11 + ellps=clrk66"))
secondary_school_district <- readShapePoly("E:/My Documents/Web
Usage/RTest/School_District_Shape_Files/Secondary School
Districts/unzipped/tl_2010_47_scsd10.shp", IDvar="NAME10",
proj4string=CRS("+proj=ll + ellps=clrk66"))
unified_school_district <- readShapePoly("E:/My Documents/Web
Usage/RTest/School_District_Shape_Files/Unified_School_Districts/Unzipped/tl_2010_47_unsd10.shp",
IDvar="NAME10", proj4string=CRS("+proj=ll + ellps=clrk66"))
plot(elem_school_district, xlim=c(-90,-83), ylim=c(35,40)
,col="green")
plot(secondary_school_district,xlim=c(-90,-83), ylim=c(35,40)
,col="blue",
add=TRUE)
plot(unified_school_district,xlim=c(-90,-83), ylim=c(35,40)
,col="lightgreen", add=TRUE)
counter=1
not_a_customer<-c(
"4700570","4700360","4700900","4701590",
"4701080",
"4701500", "4702940" )
j = 1
for (i in length(unified_school_district)) {
for (j in length(not_a_customer)){
unified_school_district$customer<-ifelse(unified_school_district$GEOID10%in%not_a_customer,1,0)
color_white_districts<-unified_school_district[unified_school_district$customer==1,]
}
}
plot(color_white_districts, xlim=c(-90,-83), ylim=c(35,40) ,
col="white",
add=TRUE)
color_white_districts
--
View this message in context:
http://r.789695.n4.nabble.com/Comparing-to-create-a-new-list-tp4633856p4634153.html
Sent from the R help mailing list archive at Nabble.com.