On Wed, 7 Nov 2007, Ingo Holz wrote: > Hi, > > I changed a specific value in the dataframe of a SpatialPolygonsDataFrame > in the following way: > > SPDF[["Name"]][1] <- 1 > > This needed a very long time (about 10 seconds).
When assigning to an existing object, in general the whole object gets recreated. With the North Carolina 100 county data set, both your version and the equivalent SPDF$Name[1] <- 1 take the same time, and the time is minimal (100 counties, 14 variables). If you can make the data available privately, and I imagine that the sizes are >> NC, I can see whether profiling provides any answers. With hundreds of thousands of polygons, you might see substantial time being used, because the memory model does not just "drop" the replacement value into the data.frame in the SPDF data slot. Is: tmp <- SPDF[["Name"]] tmp[1] <- 1 SPDF[["Name"]] <- tmp faster, slower? Is assigning to a new column name faster or slower? Note that there are two nested access functions here, the [[]] and the [] - as you probably noticed, trying to replace [1, "Name"] doesn't work because there is no [,] <- replacement method. Roger > > I have two questions: > Is there a faster way to do it? > Why did it need that much time like I did it? > > Thank you, > Ingo > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo@stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > -- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: [EMAIL PROTECTED] _______________________________________________ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo