Description Usage Arguments Value Examples
View source: R/mutate-entity.R
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.
1 | mutate_entity(world, entity, ..., ids = NULL, subset, preprocessing_fn)
|
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 |
subset |
a subset expression, e.g: age > 30. |
preprocessing_fn |
a filter function that accepts a data.table object. |
a World object.
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")
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.