The agentMatrix
class
newAgent <- new("agentMatrix",
coords = cbind(pxcor = c(1, 2, 5), pycor = c(3, 4, 6)),
char = letters[c(1, 2, 6)],
nums2 = c(4.5, 2.6, 2343),
char2 = LETTERS[c(4, 24, 3)],
nums = 5:7
)
# compare speeds -- about 5x faster
if (requireNamespace("microbenchmark", quietly = TRUE) &&
requireNamespace("sp", quietly = TRUE)) {
microbenchmark::microbenchmark(
times = 499,
spdf = {
sp::SpatialPointsDataFrame(
coords = cbind(pxcor = c(1, 2, 5), pycor = c(3, 4, 6)),
data = data.frame(
char = letters[c(1, 2, 6)],
nums2 = c(4.5, 2.6, 2343),
char2 = LETTERS[c(4, 24, 3)],
nums = 5:7
)
)
},
agentMat = {
agentMatrix(
coords = cbind(
pxcor = c(1, 2, 5),
pycor = c(3, 4, 6)
),
char = letters[c(1, 2, 6)],
nums2 = c(4.5, 2.6, 2343),
char2 = LETTERS[c(4, 24, 3)],
nums = 5:7
)
},
agentMatDirect = {
new("agentMatrix",
coords = cbind(
pxcor = c(1, 2, 5),
pycor = c(3, 4, 6)
),
char = letters[c(1, 2, 6)],
nums2 = c(4.5, 2.6, 2343),
char2 = LETTERS[c(4, 24, 3)],
nums = 5:7
)
}
)
}
#> The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
#> which was just loaded, will retire in October 2023.
#> Please refer to R-spatial evolution reports for details, especially
#> https://r-spatial.org/r/2023/05/15/evolution4.html.
#> It may be desirable to make the sf package available;
#> package maintainers should consider adding sf to Suggests:.
#> The sp package is now running under evolution status 2
#> (status 2 uses the sf package in place of rgdal)
#> Unit: microseconds
#> expr min lq mean median uq max neval
#> spdf 1234.7 1615.60 2160.6539 2216.4 2425.65 21286.2 499
#> agentMat 329.1 469.15 780.7435 611.4 690.40 73831.9 499
#> agentMatDirect 322.2 485.15 584.5986 590.1 655.65 6861.2 499