The agentMatrix class

Author

Eliot McIntire

Examples

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(require(microbenchmark)) {
  microbenchmark(times = 499,
    spdf = {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)})
}
#> Loading required package: microbenchmark
#> Unit: microseconds
#>            expr     min       lq      mean  median       uq        max neval
#>            spdf 1314.97 1391.030 1966.5100 1431.03 1568.816 210159.695   499
#>        agentMat  260.31  282.095  316.8656  299.60  331.225    628.040   499
#>  agentMatDirect  259.00  278.720  323.6870  297.30  328.580   5090.662   499
#>  cld
#>    b
#>   a 
#>   a