NLGetAgentSet {RNetLogo} | R Documentation |
Reports variable value(s) of one or more agent(s) as a data.frame (optional as a list or vector)
Description
NLGetAgentSet
is an easy way to access variable value(s) of one or more agent(s) (in a sorted way) by specifying the name of the agent or the name of an agentset containing the agents. An agent is a turtle, breed, patch, or link. An agentset is a collection of agents.
Usage
NLGetAgentSet(agent.var, agentset, as.data.frame=TRUE,
agents.by.row=FALSE, as.vector=FALSE, nl.obj=NULL)
Arguments
agent.var |
A string or vector/list of strings with the variable names of the agent(s). |
agentset |
A string specifying the agent or agentset to be queried. |
as.data.frame |
(optional) If |
agents.by.row |
(optional) This argument has an effect only in combination with |
as.vector |
(optional) Set this argument to |
nl.obj |
(optional) A string identifying a reference to a NetLogo instance created with |
Details
It's possible to use all variables of an agent, which can be found in NetLogo's Agent Monitors.
It isn't possible to get values from different types of agents (i.e. turtles, patches, links) with one
call of NLGetAgentSet
.
Value
Returns a data.frame (optional a list) with the variable value(s) of an agent/agents of an agentset.
One row for each agent and one column for each agent variable.
The result is sorted in the same manner as using sort agentset
in NetLogo, i.e. turtles are sorted by their who
variable and patches from upper left to lower right.
Author(s)
Jan C. Thiele <rnetlogo@gmx.de>
See Also
NLReport
,
NLGetPatches
,
NLGetGraph
Examples
## Not run:
nl.path <- "C:/Program Files/NetLogo 6.0/app"
NLStart(nl.path)
# NLLoadModel(...)
NLCommand("create-turtles 10")
colors <- NLGetAgentSet(c("who","xcor","ycor","color"),
"turtles with [who < 5]")
str(colors)
# or as a list (slightly faster):
colors.list <- NLGetAgentSet(c("who","xcor","ycor","color"),
"turtles with [who < 5]", as.data.frame=FALSE)
str(colors.list)
# or as a list with one list element for each agent
# (very slow!, not recommended especially for large agentsets)
colors.list2 <- NLGetAgentSet(c("who","xcor","ycor","color"),
"turtles with [who < 5]", as.data.frame=FALSE,
agents.by.row=TRUE)
str(colors.list2)
# getting the ends of links is a little bit more tricky, because they store only the
# reference to the turtles and turtles cannot directly be requested.
# A way to go is:
# create some links
NLCommand("ask turtles [ create-links-with n-of 2 other turtles ]")
link.test <- NLGetAgentSet(c("[who] of end1","[who] of end2"),"links")
str(link.test)
## End(Not run)