What Martin wants, replacing a subset, is not possible for STFDF (or other ST*) objects, just as with Spatial* objects:
library(sp) data(meuse) coordinates(meuse)=~x+y meuse[1, "zinc"] = 500 Error in meuse[1, "zinc"] = 500 : object of type 'S4' is not subsettable Indeed, as Aman suggests, this could be done by subsetting the data.frame slot, and meuse$zinc[1] = 500 is a nice/short form for meuse@data$zinc[1] = 500. the second form, meuse$zinc[1] = 500 really calls function "[<-.data.frame" whereas meuse[1,"zinc"]<-500 tries to call "[<-.SpatialPointsDataFrame", which is not available. The same is true for "[<-.STFDF". It would be helpful to get some more information why you would need to do such replacement. For the Spatial* classes this request is very rare, but in space-time everything might be different, and we'd like to hear the how/why. Best regards, On 03/11/2011 09:54 PM, Aman Verma wrote: > Hi Martin, > > It would be very helpful if you provided a clear example of exactly what you > wanted to extract from the object, but I'll make a guess. > > As the vignette (of the class STFDF) mentions, you can select a specific time > range and spatial points very easily by the normal index mechanism: the first > index is the time, and the second is the space. > > Continuing the example below, if you run > > stfdf > > It will give you three spatial points, four times, and 12 data points, one > for each space time combination. Now, if you wanted to subset this object to > select the just the first two points, and the first two times, then you could > simply say: > > stfdf[1:2,1:2] > > And you'll see that there are exactly two points, two times, and four data > points. Now, you might say, I don't want to select the "first" or the > "second" time, but I want to select by a certain time itself, like after > 11:30 on 2010-08-05. > > Take a look at the class of the stfdf@time object > > class(stfdf@time) > > You can see that it is a xts object. Check out the help file for this class: > > ?xts > > At the bottom, it gives you some great examples of how to subset these kind > of time objects. So, now, you can try using these indices instead of the > "number" of the time in your set. > > stfdf[,'2010-08-05 11:00:00::2010-08-05 12:00:00'] > > So that is how to select everything from 11:00 to 12:00 on that day. > > Now, you have to figure out how to subset the space object. You should be > able to get the idea from above though: read the help files and google how to > subset that specific object. You'll then be able to subset by index. Or, you > could find all the points within a certain window (created by a > SpatialPolygon) and then use the vector of logical as you index. > > aman > > > > > > -----Original Message----- > From: Roth, M. [mailto:m.r...@tue.nl] > Sent: March 11, 2011 3:17 PM > To: Aman Verma; r-sig-geo@r-project.org > Subject: RE: replace values in spacetime (STFDF) object > > Hi, > > thank you very much. But actually that is not exactly what I want to do. I > want to select a specific time > range and spatial points and manipulate the corresponding data. When I subset > the dataframe I must do > the selection manually and that is not that nice. > > Any idea how I could do this? > Cheers, Martin > ________________________________________ > From: Aman Verma [aman.ve...@mcgill.ca] > Sent: Friday, March 11, 2011 7:16 PM > To: Roth, M.; r-sig-geo@r-project.org > Subject: RE: replace values in spacetime (STFDF) object > > Hi Martin, > You put the brackets in the wrong place. You want to subset the dataframe, > right, not the stfdf object, so: > > stfdf@data$values[1] <- stfdf@data$values[1] + 1 > > would increase the "value" in the first row of the stfdf@data data frame. > > stfdf@data[,1] > > would get you the first column of the data frame. If you wanted to increase > the whole column by one: > > stfdf@data[,1] = stfdf@data[,1] + 1 > > aman > > -----Original Message----- > From: r-sig-geo-boun...@r-project.org > [mailto:r-sig-geo-boun...@r-project.org] On Behalf Of Roth, M. > Sent: March 11, 2011 10:00 AM > To: r-sig-geo@r-project.org > Subject: [R-sig-Geo] replace values in spacetime (STFDF) object > > Hello, > > I want to replace specific values in a STFDF object from the spacetime > package. > As example consider the following stfdf object out of the vignette. > > sp = cbind(x = c(0,0,1), y = c(0,1,1)) > row.names(sp) = paste("point", 1:nrow(sp), sep="") > sp = SpatialPoints(sp) > time = xts(1:4, as.POSIXct("2010-08-05", tz = "GMT")+3600*(10:13)) > m = c(10,20,30) # means for each of the 3 point locations > mydata = rnorm(length(sp)*length(time),mean=rep(m, 4)) > IDs = paste("ID",1:length(mydata), sep = "_") > mydata = data.frame(values = signif(mydata,3), ID=IDs) > stfdf = STFDF(sp, time, mydata) > > Now I want to do something like this: > > stfdf[ , 1]@data$values <- stfdf[ , 1]@data$values + 1 > > I get the following error: > > Error in stfdf[, 1]@data$values <- stfdf[, 1]@data$values + 1 : > object of type 'S4' is not subsettable > > Does anybody know how to do that in a correct way? > Thanks a lot, > Martin Roth > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo@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.pebe...@wwu.de _______________________________________________ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo