合并错误R

时间:2015-07-29 23:27:52

标签: r merge gis data-mapping

我正在尝试合并一些数据集。人口普查和儿童家庭很容易。相同数量的行来自同一来源。但是,我想将那些mergeddata中的变量放到地图上。为了做到这一点,我的印象是1)我已经超越了我的头脑2)我需要在我的shapefile中的邻居与人口普查和儿童家庭相对应,并且3)它是100%可能的去做。这是我发生的事情。请帮帮我。我迷路了。

人口普查和儿童家庭数据处理

 census<-read.csv(file="Census_Demographics_2010.csv") 
 childrenfamily<-read.csv(file="ChildrenFamilyHealthWellBeing2010")
     mergedData=merge(census,childrenfamily,by.x="CSA2010",by.y="CSA2010",all=TRUE)
 newData<-as.matrix(mergedData)
 edu<-read.csv(file="Education_and_Youth_2010.csv")
 MergedData=merge(mergedData,edu,by.x="CSA2010",by.y="CSA2010",all=TRUE)
 newData<-cSplit(MergedData,sep="/","CSA2010","long",type.convert=TRUE)
 NewData<-cSplit(newData,sep="-","CSA2010","long",type.convert=TRUE)
 nhood<-read.csv("nhood_2010.csv")
 nbhd<-as.matrix(nhood)
 nbhd<-cSplit(nhood,sep="/","NBRDESC","long",type.convert=TRUE)
 nbhds<-cSplit(nbhd,sep="-","NBRDESC","long",type.convert=TRUE)
 nhoods<-nbhds[order(nbhds$NBRDESC),]
 class(nhoods$NBRDESC)
 [1] "factor"
 class(newDATA$CSA2010)
 [1] "character"
 nhoods2$NBRDESC<-as.character(nhoods2$NBRDESC)
 class(nhoods2$NBRDESC)
 [1] "character"

地图标记

 library(rgdal)
 library(maptools)
 bmorehoods<-readOGR(dsn="/ladeedah/2010_Census_Neighborhoods",layer="2010_Census_Profile_by_Neighborhood_Statistical_Areas")
 library(ggplot2)
 data.points<- fortify(model=bmorehoods)
 bmore<-ggplot(data.points) + geom_polygon(aes(long, lat, group=group))

所以,我基本上有邻域数据与GIS邻域数据不匹配,我想知道

1)还有更好的方法吗? 2)为什么,当我尝试合并我的数据时,R会参与这些shananigans:

 mapdata<-merge(nhoods2,NewDATA,by.x="NBRDESC",by.y="CSA2010",all=TRUE)
 Error in merge(nhoods2, NewDATA, by.x = "NBRDESC", by.y = "CSA2010", all = TRUE) : 
  error in evaluating the argument 'y' in selecting a method for function 'merge': Error: object 'NewDATA' not found
  

0 个答案:

没有答案