Greetings:

I used to merge a SpatialPolygonsDataFrame with another dataframe with the following code (thanks to Dr. Bivand):
############################################################################################
library(maptools)
library(spgpc)
county <- readShapePoly("contUScty2000.shp", ID="GISJOIN") # put shapefile in SpatialPolygonsDataFrame
ok <- county[county$STATENAM =="Oklahoma",] # subset with "[" method
dat=data.frame(read.delim(file="okdata.txt", header = TRUE, sep = "\t", quote="\"", dec=".",na.strings = "NA"))
dat=dat[dat$Line.code=="10",]; str(dat)
ok.df<- merge(as(ok, "data.frame"), dat, by.x="NHGISCTY",by.y="FIPS", all.x=TRUE, sort=FALSE)
row.names(ok.df)=ok.df$SP_ID ######## - $SP_ID seems not to work either
ok <- SpatialPolygonsDataFrame(as(ok.df, "SpatialPolygons"), data=ok.df)

Error in as(ok.df, "SpatialPolygons") : 
  no method or default for coercing "data.frame" to "SpatialPolygons" #this is the outcome...


###########################################################################################

Unfortunatelly the last two lines are obsolete, (it seems that wrapping  "spgpc" with other packages might be the culprit) and I am lost again. I read the last discussions on the list, but was unable to solve the issue.

Please be so kind as to offer a hint.

Thanks,

mihai


      ____________________________________________________________________________________

[[elided Yahoo spam]]
	[[alternative HTML version deleted]]


