[R-sig-Geo] change a column name of the data slot

Roger Bivand Roger.Bivand at nhh.no
Wed Mar 12 17:54:30 CET 2008


On Wed, 12 Mar 2008, G. Allegri wrote:

> I'm trying to change a column name of the data slot of a SpatialPixelsDataFrame.
> I've added the column this way:
>
>> slot(EceZKRIG0_3,"data")[,index]<-Sim_mean_approx[[2]]
>
> The column added is V151 (as 151 is the actual index).
> I want to rename it, and I've tried:
>
>> names(slot(EceZKRIG0_3,"data")[index])<-"Mean_approx"

The point of the Spatial*DataFrame classes is to look like GIS to GIS 
people and data.frames to data people. Isn't it easier just to say:

EceZKRIG0_3$Mean_approx <- Sim_mean_approx[[2]]

There is also a names()<- method, so if you wanted to change a name, you 
could do it:

names(EceZKRIG0_3)[151] <- "Mean_approx"

library(sp)
data(meuse)
coordinates(meuse) <- c("x", "y")
class(meuse)
names(meuse)
meuse$s_lime <- sample(meuse$lime)
names(meuse)
names(meuse)[13] <- "not_slime"
names(meuse)

OK? Isn't that easier?

Roger

>
> No errors are raised, but the column remain V151. What's wrong?
>
> Giovanni
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no




More information about the R-sig-Geo mailing list