EDIT: Should be applicable in NetLogo 5.3.1.
My problem:
I have two lists in NetLogo, for example [13 8 2 20 8]
and [7 7 7 7 7]
which are both of same length. I want to subract the latter list from earlier item by item, i.e. [(13-7) (8-7) (2-7) (20-7) (8-7)].
Thus the result must be: [6 1 -5 13 1]
In R it is very easy:
> a <- c(13, 8, 2, 20, 8)
> b <- rep(7, 5)
> c <- a - b
> print(c)
[1] 6 1 -5 13 1
Unfortunately, NetLogo does not work in such a convenient way.
My question: How to code this in NetLogo?
If your lists have the same length you can use map
to perform operations on multiple lists. The given reporter is then run once for all first items, then once for all second items, ... . The result is then a list of the same length as the input lists.
show (map - [13 8 2 20 8] [7 7 7 7 7])
observer: [6 1 -5 13 1]