[R-sig-Geo] iterative field naming
Edzer Pebesma
edzer.pebesma at uni-muenster.de
Thu Dec 29 12:15:40 CET 2011
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
--
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
8333081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de
http://www.52north.org/geostatistics e.pebesma at wwu.de
More information about the R-sig-Geo
mailing list