Skip to contents

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 new()

Usage

Neighbors$new(agents = list())


Method map()

Usage

Neighbors$map(.f)

Arguments

.f

Function to apply to each neighbor agent


Method length()

Number of neighbor agents, i.e., length of the neighbors agent list.

Usage

Neighbors$length()


Method get()

Get a neighbor by index or name

Usage

Neighbors$get(key)

Arguments

key

An integer index or character name of the neighbor

Returns

An Agent instance


Method filter()

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


Method sample()

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

Usage

Neighbors$add(...)

Arguments

...

Agent objects to add


Method remove()

Remove one or more agents from the neighbors list

Usage

Neighbors$remove(...)

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.