nOf: N random 'agents'

nOfR Documentation

N random agents

Description

Report n patches or turtles randomly selected among agents.

Usage

nOf(agents, n)

## S4 method for signature 'matrix,numeric'
nOf(agents, n)

Arguments

agents

Matrix (ncol = 2) with the first column pxcor and the second column pycor representing the patches coordinates, or

          Matrix (`ncol` = 3) with the first column "`pxcor` and the second
          column `pycor` representing the `patches` coordinates and the
          third column `id`, or

          `AgentMatrix` object representing the moving `agents`, or

          Matrix (`ncol` = 2) with the first column `whoTurtles` and the
          second column `id`.
n

Integer. Number of patches or turtles to select from agents.

Details

n must be less or equal the number of patches or turtles in agents.

     If `agents` is a matrix with `ncol` = 3, the selection of `n`
     random `patches` is done per individual "id". The order of the `patches`
     coordinates returned follow the order of "id".
     If `agents` is a matrix (`ncol` = 2) with columns `whoTurtles` and
     `id`, the selection of `n` random `turtles` (defined by their `whoTurtles`)
     is done per individual "id". The order of the `who` numbers returned
     follow the order of "id".

Value

Matrix (ncol = 2, nrow = n) with the first column pxcor and the second column pycor representing the coordinates of the selected patches from agents, or

    Matrix (`ncol` = 2) with the first column `pxcor`
    and the second  column `pycor` representing the coordinates of the
    selected `patches` from `agents`, `n` per individual "id", or

    `AgentMatrix` (`nrow` = `n`) representing the `turtles`
    selected from `agents`,

    Integer. Vector of `who` numbers for the selected `turtles` from
    `agents`, `n` per individual "id".

Author(s)

Sarah Bauduin

References

Wilensky, U. 1999. NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University. Evanston, IL.

See Also

https://ccl.northwestern.edu/netlogo/docs/dictionary.html#n-of

Examples

# Patches
w1 <- createWorld(minPxcor = 0, maxPxcor = 4, minPycor = 0, maxPycor = 4)
pSelect <- nOf(agents = patches(w1), n = 5)

# Turtles
t1 <- createTurtles(n = 10, coords = randomXYcor(w1, n = 10))
tSelect <- nOf(agents = t1, n = 2)


PredictiveEcology/NetLogoR documentation built on Jan. 31, 2024, 9:31 p.m.