netlogo - count the number of occurrences of each item in a list -


i have list 20 items , want count number of occurrences of each item in list.i know code below

to-report frequency [i lst] report length filter [? = i] list end 

but not want write 20 lines like

let c1 frequency 1 (list1) let c2 frequency 2 (list1) . . . let c20 frequency 20 (list1) 

that's:

map [frequency ? list1] n-values 20 [? + 1] 

sample run:

observer> set list1 [1 4 4 7 10 10 10 14] observer> show map [frequency ? list1] n-values 20 [? + 1] observer: [1 0 0 2 0 0 1 0 0 3 0 0 0 1 0 0 0 0 0 0] 

Comments

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -