[R-sig-Geo] iterative field naming
Jordan Chamberlin
chamb244 at msu.edu
Thu Dec 29 13:51:31 CET 2011
Thank you, Edzer, Tom and Tom. Problem solved!
On 11/12/29 6:15 AM, Edzer Pebesma wrote:
> Jordan, please try
>
> zmbpts[[myfname]]<- extr$band1
>
> On 12/29/2011 12:19 AM, Jordan Chamberlin wrote:
>> Dear people,
>>
>> Apologies in advance for what must be a silly question: I want to
>> iterative add a field to a dataframe, where the field takes a name that
>> is created as part of the iteration. In the bit of code below, the
>> problem line is "zmbpts$myfname<- extr$band1" : what I want to do is
>> have the value of the string "myfname" be used as the name of the new
>> field (rather than creating a new field called "myfname", which is what
>> I'm doing).
>>
>> for (i in 2000:2009) {
>> for (j in 1:12) {
>>
>> #temporarily go to data directory, grab file, then return to
>> working directory
>> setwd(mydd)
>> myingrid<- gsub("( )", "", paste("pre", i, "_", j))
>> tmpgrid<- readGDAL(myingrid)
>> setwd(mywd)
>>
>> #create SpatialPixelsDataFrame
>> spdf<- as(tmpgrid, "SpatialPixelsDataFrame")
>> #summary(spdf)
>> #image(spdf, "band1", axes=TRUE, col=terrain.colors(20))
>>
>> #extract values to points
>> proj4string(spdf)<-proj4string(zmbpts)
>> extr = over(zmbpts,spdf)
>>
>> #add extracted values to SpatialPointsDataFrame
>> myfname<- gsub("( )", "", paste("y", i, "m", j))
>> zmbpts$myfname<- extr$band1
>>
>> }
>> }
>>
>> Thanks for your kind help! Jordan
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
More information about the R-sig-Geo
mailing list