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

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -