Hi, I have a cloud of randomly distributed points in 2-dimensional space and
want to set up a grid, with a given grid-cell size, that minimizes the distance
between my points and the grid nodes. Does anyone know of an R function or
toolbox that somehow addresses this problem? This is a problem o
How about this?
require(FNN)
#FOR DEMONSTRATION PURPOSES, GENERATE 2D DATA
set.seed(3242)
X <- matrix(runif(50),ncol=2)
plot(X,pch=16,cex=1.5, asp=1)
#PLOT GRID
grid <- as.matrix(expand.grid(seq(0,1,by=.1),seq(0,1,by=.1)) )
abline(v=unique(grid[,1]),col="#FF30")
abline(h=unique(grid[,2]),co
Gonçalo,
Interesting question. You can use the optim() function to optimize a
function over two dimensions. Here's an example.
# some clumpy "cloud" data
myx <- c(0.3 + rnorm(50, 0, 0.05), 0.7 + rnorm(50, 0, 0.05))
myy <- c(0.45 + rnorm(50, 0, 0.05), 0.65 + rnorm(50, 0, 0.05))
# size of the fi
3 matches
Mail list logo