Learn R Programming

RNetLogo (version 0.9.4)

NLSetAgentSet: Sets a variable of one or more agents to value(s) in a data.frame or vector.

Description

NLSetAgentSet is an easy way to set the variable value(s) of one or more agents (by specifying the name of the agent or the name of an agentset containing the agents) to the value(s) of a data.frame or vector.

Usage

NLSetAgentSet(agentset, input, var.name=NULL, nl.obj=NULL)

Arguments

agentset
A string specifying the agent or agentset for which values should be changed.
input
A data.frame or vector. If a data.frame, it must have one column with the corresponding agent agent variable name for each agent variable to be set and one row for each agent. The rows have to be sorted in the order NetLogo is processing the agentse
var.name
If input is a simple vector instead of a data.frame it gives the name of the agent variable as a string which should be set with the values of the vector submitted in input. With a vector you can only set one agent variable at a
nl.obj
(optional) A reference to a NetLogo instance created with NLStart.

Value

  • No return value.

Details

The agent variable values contained as columns in the input data.frame are changed. The columns of the data.frame have to be named exacly like the agent variable which should get the values. The rows have to be sorted as NetLogo would process the agentset using the sort reporter.

See Also

NLSetPatches, NLGetAgentSet, NLGetGraph, NLDfToList

Examples

Run this code
nl.path <- "C:/Program Files/NetLogo 5.0.3"
NLStart(nl.path)
# NLLoadModel(...)
ag <- NLGetAgentSet(c("xcor","ycor"),"turtles")
ag2 <- data.frame(xcor=ag$xcor, ycor=ag$xcor)
NLSetAgentSet("turtles", ag2)

Run the code above in your browser using DataLab