Search code examples
netlogoagentset

Netlogo - Given an Agentset of 2+ Turtles, find the most frequent color


Given an agentset of two or more turtles, how do I find the most frequent color?

I would like to do something like that, if possible:

set my_color [mostfrequentcolor] of my_agentset

Solution

  • You're looking for the modes primitive (https://ccl.northwestern.edu/netlogo/docs/dictionary.html#modes):

    one-of modes [color] of my_agentset
    

    It's "modes", plural, since there could be a tie. One way of breaking the tie is to use one-of to make a random selection.