Description Usage Arguments Value Examples
Organise a field of weighted particles by grouping clusters.
1 2 3 |
xyzm |
data.table, or object coercible to one;
4- (or 3- if |
cdh, cdv |
numeric [1];
horizontal and vertical search radii for finding nearby particles; the
search region around each particle is a circle ( |
mm |
numeric [1]; minimum mass for resulting particles: particles below this mass are coalesced with the nearest particle even if outside the search radius |
subregions |
logical [1]; use subregions? Highly recommended for vast performance increases: will sort particles into rectangular subregions before coalescing so that particle distances will only be calculated between particles in the same subregion, with the sacrifice that the occasional grouping will be missed for particle pairs straddling subregion boundaries. Automatically switches off for data sets that are too small to benefit. |
nppsr |
integer [1]; if using subregions, how many particles should there be in each subregion, at least; 256 highly recommended as generally the best compromise |
TwoD |
logical [1];
set to |
na.rep |
logical [1];
rows which contain NAs are removed prior to coalescing; set
|
maxnp |
integer [1] or |
maxbymm |
not used |
print.timings |
logical [1];
put |
a data.table with columns:
..$x,y,z
(num): z
only if not TwoD
..$m
(num): mass/ weight
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | library(graphics)
library(data.table)
tps <- test.points(100L, TRUE)
# total mass and centre of mass
sum(tps$m)
tps[, lapply(list(x = x, y = y), weighted.mean, m)]
# plot original points - size represents mass
plot(tps[, .(x, y)], cex = tps$m*2, pch = 16L)
cps1 <- coalesce(tps, 5, TwoD = TRUE)
cps2 <- coalesce(tps, 10, TwoD = TRUE)
# total mass and centre of mass should be unchanged
sum(cps1$m)
cps1[, lapply(list(x = x, y = y), weighted.mean, m)]
sum(cps2$m)
cps2[, lapply(list(x = x, y = y), weighted.mean, m)]
points(cps1[, .(x, y)], cex = cps1$m*2, pch = 16L, col = "red")
points(cps2[, .(x, y)], cex = cps2$m*2, pch = 16L, col = "blue")
points(tps[, .(x, y)], cex = tps$m*2)
legend("bottom", legend = c("original", "cdh = 5", "cdh = 10"),
ncol = 3L, col = c("black", "red", "blue"), pch = 16L,
bg = "white")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.