Learn R Programming

RNetLogo (version 1.0-4)

NLSetAgentSet: Sets a variable of one or more agent(s) 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 agent(s) (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 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 agentset with sort agentset (e.g. turtles are sorted by their who value). If a vector, only one agent variable can be set and the name has to be given by the optional argument var.name.

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 time.

nl.obj

(optional) A string identifying 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 exactly 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 6.0/app"
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