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