Neighbors class
Neighbors class
Value
list of return values from applications of .f
Details
A container for an agent's neighbors, with utilities for iteration, filtering,
sampling, and modification.
Methods
Method map()
Arguments
.f
Function to apply to each neighbor agent
Number of neighbor agents, i.e., length of the neighbors agent list.
Get a neighbor by index or name
Arguments
key
An integer index or character name of the neighbor
Returns
An Agent instance
Filter neighbors using a predicate function
Usage
Neighbors$filter(predicate)
Arguments
predicate
A function taking an Agent and returning TRUE or FALSE
Returns
A new Neighbors object containing only the filtered agents
Sample one or more neighbors
Usage
Neighbors$sample(n = 1, replace = FALSE, weights = NULL)
Arguments
n
Number of neighbors to sample
replace
Logical: sample with replacement?
weights
Either a numeric vector or a function returning weights for each agent
Returns
A Neighbors object or a single Agent depending on n
Method add()
Add one or more agents to the neighbors list
Remove one or more agents from the neighbors list
Arguments
...
Agent objects to remove
Method clone()
The objects of this class are cloneable with this method.
Usage
Neighbors$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.