Description Usage Arguments Details Value Author(s) See Also Examples
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.
1 2 | NLGetAgentSet(agent.var, agentset, as.data.frame=TRUE,
agents.by.row=FALSE, as.vector=FALSE, nl.obj=NULL)
|
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 |
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
.
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.
Jan C. Thiele <rnetlogo@gmx.de>
NLReport
,
NLGetPatches
,
NLGetGraph
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | ## 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.