[R-sig-Geo] assign a slot to a name (character) in loop

ipampa ipaajs at gmail.com
Sun Jul 14 14:33:47 CEST 2013


I have been struggling for a long time with this, and I still don´t know how
to achieve it.

I have many databases that I want to cut and put in different objects and I
would need to be able to use the function get() before the assignment. I
mean I need the last loop of this script to work:


################ data ################
library(sp)
grd <- GridTopology(c(1,1), c(1,1), c(3,3))
polys <- as.SpatialPolygons.GridTopology(grd)
centroids <- getSpPPolygonsLabptSlots(polys)
x <- centroids[,1]
y <- centroids[,2]
z <- 1.4 + 0.1*x + 0.2*y + 0.002*x*x
map <- SpatialPolygonsDataFrame(polys, 
                                data=data.frame(x=x, y=y, z=z,                                
row.names=getSpPPolygonsIDSlots(polys)))


########## my case ##############
new.data1<-data.frame(x=x, y=y, z=z*2,
row.names=getSpPPolygonsIDSlots(polys))
new.data2<-data.frame(x=x, y=y, z=z/2,
row.names=getSpPPolygonsIDSlots(polys))
datas<-c("new.data1","new.data2")
maps<-c("map1","map2")

##################################
######### help please!!! ###############
##################################
for(i in 1:length(datas)){
  slot(get(maps[i]),"data")<-get(datas[i])
}


anybody any suggestions??
thanks million

Iosu





--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/assign-a-slot-to-a-name-character-in-loop-tp7584131.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list