Displaying 1 result from an estimated 1 matches for "xyzsel".
2012 Oct 30
1
mapply instead for loop
...<- 1:10
xyz <- data.frame(expand.grid(x,y)[1], expand.grid(x,y)[2], z = rnorm(100))
names(xyz) <- c("x", "y", "z")
head(xyz)
size <- 2
output <- NULL
### for loop
for(i in 1:dim(xyz)[1]){
x0 <- xyz[i, "x"]
y0 <- xyz[i, "y"]
xyzSel <- xyz[xyz$x >= (x0 - size) & xyz$x < (x0 + size) & xyz$y >= (y0 - size) & xyz$y < (y0 + size), ]
output[i] <- min(xyzSel$z)
}
output
[[alternative HTML version deleted]]