Last chance! 50% off unlimited learning
Sale ends in
NLGetPatches
is an easy way to access variables of all patches (default) or of
a subset of patches.NLGetPatches(patch.var, patchset="patches", as.matrix=FALSE,
as.data.frame=TRUE, patches.by.row=FALSE,
as.vector=FALSE, nl.obj=NULL)
TRUE
(default is FALSE
), the function will return the result as a matrix representing the NetLogo world.
(This option is Only available, if the argument patchset
is not used, i.e. ifTRUE
(default) the function returns a data.frame with one column for each patch.var
and one row for each patch.
The column names are taken from the names of the patch.var
argument.
If FALS
as.data.frame=FALSE
, i.e. when a list is returned.
If patches.by.row=FALSE
(default) the returned list contains one list element for each patch.var
TRUE
for getting the result as a simple vector in case of requesting only one patch variable.
This is the fastest way to access one patch variable. It does not make sense to set this variable to TRUE
NLStart
.sort patchset
in NetLogo, e.g. patches are sorted from upper left to lower right.
To get the same result as with default settings until RNetLogo version 0.9.2 use: as.data.frame=FALSE
and patches.by.row=TRUE
.performanceNotes.pdf
for performance details and notes on changes since version 0.9.3.NLReport
,
NLGetAgentSet
,
NLGetGraph
nl.path <- "C:/Program Files/NetLogo 5.0.3"
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)
Run the code above in your browser using DataLab