NLGetAgentSet(RNetLogo)
NLGetAgentSet()所属R语言包:RNetLogo
Reports the values of the variables of the agent or agentset as a data.frame (optional as a list or vector)
报告代理变量的值,或作为数据框(可选作为一个列表或矢量agentset)
译者:生物统计家园网 机器人LoveR
描述----------Description----------
NLGetAgentSet is an easy-to-use way to access variables of an agent or an agentset (in a sorted way). An agent is a turtle, breed, patch, or link. An agentset is a collection of agents.
NLGetAgentSet是一个易于使用的方式来访问代理变量或agentset的排序方式。代理是一只乌龟,品种,补丁,或链接。一个agentset是一家集代理。
用法----------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 names of the agent/agentset variables.
一个字符串或向量/字符串列表的名字的代理/ agentset的变量。
参数:agentset
A string specifying the agent or agentset to be queried.
一个字符串,指定代理或要查询agentset。
参数:as.data.frame
(optional) If TRUE (default) the function will return a data.frame with a column for each agent.var and a row for each agent. The column names are taken from the names of the agent.var argument. If FALSE the function will return a list instead of a data.frame (a little bit faster, when not using agents.by.row=TRUE) .
(可选)如果TRUE(默认),该函数将返回一个数据框一列每个agent.var和一排,每个代理。列名agent.var参数的名字。如果FALSE的功能将返回一个列表,而不是一个数据框(快一点点,不使用时agents.by.row=TRUE)。
参数:agents.by.row
(optional) Has an effect only in combination with as.data.frame=FALSE, i.e. a list should be returned. If agents.by.row=FALSE (default) the returned list contains one list element for each agent.var. Each list element contain a vector with the values of the different agents (agentset). If agents.by.row=TRUE the returned list contains one list element for each agent. Each list element contain a vector with the values of the different request agent variables (agent.var). Attention: agents.by.row=TRUE makes the function very slow, especially when many agents are requested.
(可选)的效果,只有在搭配as.data.frame=FALSE,即应该返回的列表。如果agents.by.row=FALSE(默认)返回的列表中包含一个列表中为每个agent.var元素。每个列表元素包含一个矢量的值不同的行为(agentset)。如果agents.by.row=TRUE返回的列表包含一个列表中的元素为每一个代理商。每个列表元素包含一个矢量的值的不同要求代理变量(agent.var)。注意:agents.by.row=TRUE功能很慢,尤其是当很多代理商要求。
参数:as.vector
(optional) If you request only one agent variable you can ask for getting the result as a simple vector by setting this argument to TRUE. This is the fastest way to access one agent variable. It does not make sense to set this variable to TRUE together with as.data.frame=TRUE, but as.vector is processed first and will win the race if you accidently set as.data.frame to TRUE as well. By default as.vector is FALSE.
(可选)如果你只要求一个代理变量,你可以问得到的结果作为一个简单的矢量将此参数设置为TRUE。这是最快的方式来访问一个代理变量。不设置这个变量TRUE一起as.data.frame=TRUE,但as.vector是先处理,并会赢得比赛,如果你不小心设置as.data.frame到<X >为好。默认情况下TRUE是as.vector。
参数:nl.obj
(optional) A variable holding a reference to a NetLogo instance created with NLStart.
(可选)变量参考到的NetLogo实例的创建与NLStart。
Details
详细信息----------Details----------
It's possible to use all the variables of an agent, which can be found in the inspect window. It isn't possible to get values from different types of agents (i.e. turtles, patches, links) with one call of NLGetAgentSet. See the document performanceNotes.pdf in directory performanceNote in the installation directory of the package for performance details.
这是可能的,使用代理,可以发现在检查窗口中的所有变量。这是不可能的,不同类型的代理(即龟,修补程序,链接)的一个调用的NLGetAgentSet值。请参阅文档performanceNotes.pdf目录中的performanceNote的安装目录中的包的性能的详细信息。
值----------Value----------
Returns a data.frame (optional a list) with the value(s) of the agent/agentset variable(s). One row for each agent and one column for each agent variable. The result is sorted (like using sort agentset in NetLogo, e.g. turtles are sorted by their who variable) and patches from upper left to lower right.
返回一个数据框(可选的列表)的值(s)的代理/ agentset的变量(s)。一排的每个代理,每个代理变量的一列。结果排序(一样使用sort agentset的NetLogo,例如海龟进行排序who变量)和补丁程序,从左上角到右下角。
To get the same result as with default settings until RNetLogo version 0.9.2 use: as.data.frame=FALSE and agents.by.row=TRUE.
为了得到相同的结果,使用默认设置,直到RNetLogo版本0.9.2使用方法:as.data.frame=FALSE和agents.by.row=TRUE。
(作者)----------Author(s)----------
Jan C. Thiele <jthiele@gwdg.de>
参见----------See Also----------
NLReport, NLGetPatches, NLGetGraph
NLReport,NLGetPatches,NLGetGraph
实例----------Examples----------
## Not run: [#不运行:]
NLStart("C:/Program Files/NetLogo 5.0")
# NLLoadModel(...)[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)[(很慢,不建议使用,尤其是对大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 more tricky, since they store only the[获得链接的两端是有点棘手,因为他们只存储]
# reference to the turtles and turtles can not direcly be requested. [参考海龟和乌龟不能direcly要求。]
# Here comes the solution:[这里谈到的解决方案:]
link.test <- NLGetAgentSet(c("[who] of end1","[who] of end2"),"links")
str(link.test)
## End(Not run)[#(不执行)]
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|