NLGetPatches {RNetLogo} | R Documentation |
Reports the values of patch variables as a data.frame (optional as a list, matrix or simple vector)
Description
NLGetPatches
is an easy way to access variables of all patches (default) or of
a subset of patches.
Usage
NLGetPatches(patch.var, patchset="patches", as.matrix=FALSE,
as.data.frame=TRUE, patches.by.row=FALSE,
as.vector=FALSE, nl.obj=NULL)
Arguments
patch.var |
A string or vector/list of strings with the names of patch variables to report. |
patchset |
(optional) A string defining which patches to request. By default, values of all patches are returned. |
as.matrix |
(optional) If this variable is |
as.data.frame |
(optional) If |
patches.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 the variables of a patch, which can be found in NetLogo's Agent Monitors.
Value
Returns a data.frame (optional a list) with the variable value(s) of a patch/patches of a patchset.
One row for each patch and one column for each patch variable.
The result is sorted (like using sort patchset
in NetLogo), e.g. patches are sorted from upper left to lower right.
Author(s)
Jan C. Thiele <rnetlogo@gmx.de>
See Also
NLReport
,
NLGetAgentSet
,
NLGetGraph
Examples
## Not run:
nl.path <- "C:/Program Files/NetLogo 6.0/app"
NLStart(nl.path)
# NLLoadModel(...)
allpatches <- NLGetPatches(c("pxcor","pycor","pcolor"))
str(allpatches)
# only a subset of patches
subsetpatches <- NLGetPatches(c("pxcor","pycor","pcolor"),
"patches with [pxcor < 5]")
str(subsetpatches)
# or as a list (slightly faster):
colors.list <- NLGetPatches(c("pxcor","pycor","pcolor"),
"patches with [pxcor < 5]", as.data.frame=FALSE)
str(colors.list)
# or as a list with one list element for each patch
# (very slow!, not recommended especially for large patchsets)
colors.list2 <- NLGetPatches(c("pxcor","pycor","pcolor"),
"patches with [pxcor < 5]", as.data.frame=FALSE,
patches.by.row=TRUE)
str(colors.list2)
## End(Not run)