Skip to content
Prev 17281 / 29559 Next

Shape file problem

On Wed, Jan 30, 2013 at 2:42 PM, Milan Sharma <milansharma2012 at yahoo.com> wrote:

            
Well, we don't know how you created the shapefile so we can't solve
that problem.
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
...
Message-ID: <CANVKczM35dbMDf7K926CiG7cOi3N_1W+K37KVUWNfqzmTVUZ+Q@mail.gmail.com>
In-Reply-To: <f44309e2b70d48e5935aef001229da43@EX-0-HT0.lancs.local>