【发布时间】:2014-01-22 13:33:16
【问题描述】:
如何以适当的方式分配一个巨大的距离矩阵以避免“分配是 无法”错误。假设您有 100.000 个点随机分布在一些 空间。如何巧妙地创建一个矩阵或“dist”对象,它表示 DistMatrix 的一半。也许它应该是另一个对象,它将能够有效地分配大量的距离。
您可以从以下链接获取多边形对象: https://www.dropbox.com/sh/65c3rke0gi4d8pb/LAKJWhwm-l
# Load required packages
library(sp)
library(maptools)
library(maps)
# Load the polygonal object
x <- readShapePoly("vg250_gem.shp")
# Sample or Pick up a large Number of Points
# this command needs some minutes to be done.
# "coord" is SpatialPoints Object
n <- 1e5
coord <- spsample(x, n, "random")
# Try to measure the distances by dist()
DistMatrix <- dist(coord@coords)
Error: negative length vectors are not allowed
# Try to measure the distances by spDists()
DistMatrix <- spDists(coord)
Error: cannot allocate vector of size (some number) MB
# It seems that the problem lies on large matrix to be created.
如何在 R 中解决大量“n”的问题。
【问题讨论】:
标签: r distance spatial allocation euclidean-distance