Reputation: 137
I make agents with a random-float color statement
ask turtles [set color random-float 100 ]
I get color number such as 213.45 and 23.67. This is fine. My question however is how to count the frequency of a specific category of colors (for example: 213.45: 5 times) and the total number of colors. I need a reporter. I know how to list colors:
to-report color-turtles
report [color] of turtles
end
but I don't know how I can count them.
EDIT: . instead of ,
Upvotes: 1
Views: 158
Reputation: 9620
First of all, when doing science, always use the point as a decimal separator.
Second, you need to say what you mean by a "specific category". If you truly mean specific (in your example, 213.45), then the answer is each category occurs once. (Or else there is something wrong with random-float.) So what you really need to do is histogram your data, where you specify the bins. Unfortunately, NetLogo does not build in this functionality. See https://github.com/NetLogo/NetLogo/issues/367
Here is how I would do it. Build a reporter procedure that puts each color in a category and report the category. (The simples approach would be to round to an integer.) Use the table extension to increment the count by 1 each time you encounter the category.
Edit:
If you already know the colors, you could get a count for any color by using
to-report countColor [#color]
report count (turtles with [color = #color])
end
For example,
to-report color-count
let _colors remove-duplicates ([color] of turtles)
let _cts map [countColor ?] _colors
report (map list _colors _cts)
end
Upvotes: 2