Skip to content
Prev 3797 / 29559 Next

SGDF loop processing time

On Wed, 25 Jun 2008, Ilona Naujokaitis-Lewis wrote:

            
Hi,

It reached me, not sure about the list - the posting guide on R-help sets 
out the attachments policy.

library(sp)
load("IlonaQuesRgeo.RData")

Patchmap$HSvalue <- HSmap$HSvalue
Patchmap_orig <- Patchmap
fullgrid(Patchmap) <- FALSE
gridded(Patchmap) <- FALSE
# drop back to points to split on ID

Patchmap0 <- Patchmap[Patchmap$ID==0,]
Patchmap1 <- Patchmap[Patchmap$ID==1,]
# split subsets

Patchmap0$NPHS <- ifelse(Patchmap0$HSvalue < HSthreshold,
   Patchmap0$HSvalue, NA)
# vectorised ID==0 (is the else value correct?)

Patchmap1$NPHS <- round(rnorm(length(Patchmap1$ID), mean_HS,
   sd_HS),digits=3)
Patchmap1$NPHS <- ifelse(Patchmap1$NPHS < new_HSthreshold,
   Patchmap1$HSvalue, Patchmap1$NPHS)
# vectorised ID==1 (is the else value correct?)

Patchmap_res <- rbind(Patchmap0, Patchmap1)
gridded(Patchmap_res) <- TRUE
fullgrid(Patchmap_res) <- TRUE
# put back together, re-sorting to get back in place

all.equal(Patchmap_res$ID, Patchmap_orig$ID)
# sanity check on IDs

Patchmap_orig$NPHS <- Patchmap_res$NPHS
# assign back if need be and display image
image(Patchmap_orig, "NPHS")

There must be better ways, the workflow is a little contorted, but it may 
be worth trying. Maybe a set.seed() to anchor the rnorm()?

Hope this helps,

Roger