Shape file problem
On Wed, Jan 30, 2013 at 2:42 PM, Milan Sharma <milansharma2012 at yahoo.com> wrote:
#in my shape file, column names have come #SD_csv_O, SD_CSV_D,instead of open water, #or other names like that because of my problem in creating shape file.
Well, we don't know how you created the shapefile so we can't solve that problem.
# I wanted to assign the correct names of my columns using names (data). But got error colnames(data) <- c( "STATEFP","COUNTYFP","COUNTYNS" , "GEOID", "NAME","NAMELSAD","LSAD","CLASSFP","MTFCC","CSAFP","CBSAFP","METDIVFP","FUNCSTAT","ALAND","AWATER","INTPTLAT","INTPTLON", "Openwater","Dev open","DevLowin","DevMed","DevHi","Barren","Deciduous","Evergr","Mixfor","Shrub","Grass","Sedge","Cultcrop","Woody","wetHerb","p2010","Areasqml","Popsqm")
Error in `colnames<-`(`*tmp*`, value = c("STATEFP", "COUNTYFP", "COUNTYNS",
Why did you say "using names (data)" and then try "colnames(data)"?
Because "names(data)" should work. Here is a complete reusable
example:
> require(sp)
> data=data.frame(x=runif(10),y=runif(10),z1=runif(10),z2=runif(10))
> coordinates(data)=~x+y
> data
coordinates z1 z2
1 (0.724746, 0.557815) 0.47356654 0.93721636
2 (0.614448, 0.10798) 0.80956133 0.78836015
3 (0.39065, 0.845377) 0.61940167 0.36847489
4 (0.35598, 0.363572) 0.07214902 0.45609632
5 (0.248248, 0.219995) 0.64276010 0.52574029
...
> colnames(data)
NULL
> names(data)
[1] "z1" "z2"
> colnames(data)=c("foo","bar")
Error in `colnames<-`(`*tmp*`, value = c("foo", "bar")) :
'dimnames' applied to non-array
> names(data)=c("foo","bar")
> data
coordinates foo bar
1 (0.724746, 0.557815) 0.47356654 0.93721636
2 (0.614448, 0.10798) 0.80956133 0.78836015
3 (0.39065, 0.845377) 0.61940167 0.36847489
4 (0.35598, 0.363572) 0.07214902 0.45609632
5 (0.248248, 0.219995) 0.64276010 0.52574029
6 (0.955221, 0.185988) 0.93994016 0.64672931
...