mutate_entity: Mutate entities

Description Usage Arguments Value Examples

View source: R/mutate-entity.R

Description

This function allows the attribute data of any Entity instance and its inheritances stored in World to be mutated.

It is useful for updating attribute variables, such as age of entities in each iteration etc. Note that, only one or none of the filter strategies ids, subset, preprocessing_fn should be used at a time.

Usage

1
mutate_entity(world, entity, ..., ids = NULL, subset, preprocessing_fn)

Arguments

world

a World object.

entity

a character denoting an entity classname.

...

a mutate expression using data.table syntax, e.g: age := age +1

ids

a integer vector containing ids of entity to be mutated.

subset

a subset expression, e.g: age > 30.

preprocessing_fn

a filter function that accepts a data.table object.

Value

a World object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
create_toy_world()

# increase age of all individual agents by 1 year.
world %>% mutate_entity(entity = "Individual", age := age + 1L)

# increase age of all female individual agents by 1 year.
world %>% mutate_entity(entity = "Individual", age := age + 1L, subset = sex == "female")

# incrementally increase age of all individual agents by 1 year in each iteration

for (i in 1:10) {
  world %>% mutate_entity(entity = "Individual", age := age + 1L, subset = sex == "female")
}

dymium-org/dymiumCore documentation built on July 18, 2021, 5:10 p.m.