1

I'm creating a list out of the patch variable "geb-id" (a 7-digit integer number) with the following line:

set geb-id-list [geb-id] of patches with [geb-id >= 0 AND residents != 0]

When I look at the produced list, all looks fine. Then I'm using

set geb-id-list remove-duplicates geb-id-list

to remove the duplicates, as there are several patches with the same geb-id but I only want one geb-id per list. The list now doesn't contain any duplicates anymore, but some of the numbers have turned into random floating point numbers and I cannot trace back where these numbers suddenly came from (I checked the source data and they don't contain any floating point numbers).

For example:

The list with duplicates:

[ 133349 133349 133351 133351 133351 133360 133360 133360 133375 133375 133375 ]

The list without duplicates:

[ 133349 133351 133360 209587.61538461538 133915.6666666667 1518018.2 133375 ]

The floating point numbers that appear in the list without duplicates do not appear in the original list (even when removing the digits after the comma).

Here is the list with with the geb-id's as a csv file.

misch
  • 11
  • 3
  • 1
    Is there any way you can post your source data as a CSV or the procedure that generates it (if it's not from a file)? Running `show remove-duplicates [ 133349 133349 133351 133351 133351 133360 133360 133360 133375 133375 133375 ]` in the command center gives `[133349 133351 133360 133375]` as expected. – Jasper Aug 16 '22 at 18:52
  • I can't provide the source data, but I used the csv:to-file function from the csv-extension to copy the original list into an excel file. I hoped that when I would read in the data again ( with csv:from-file) as a new list (and removing the "NaN" values) it would magically solve my problem. But it didn't, I still get the floating point numbers as soon as I apply the remove-duplicates function. I attached the csv-file in my question above. – misch Aug 17 '22 at 15:48
  • Looking at your csv file, you do have some floating point numbers in there, for example 209587.615384615. You probably just formatted them in a way that rounds them to a whole number which is why you didn't notice them right away. – LeirsW Aug 18 '22 at 12:30
  • It's realllllllllllly unlikely that there's a bug in `remove-duplicates`, so you should do your best to absolutely rule out other explanations first. – Seth Tisue Aug 23 '22 at 01:05

1 Answers1

2

I think your source data does have floating point values in it. When I use your provided CSV and run this code:

extensions [csv]

to check-floats
  let values-2d csv:from-file "geb-id-list.csv"
  let values map [ r -> item 0 r ] values-2d 
  let nums filter [ v -> v != "NaN" ] values
  let floats filter [ n -> floor n != n ] nums
  show floats
end

The check-floats outputs [2079045.4999999998 2111524.956521739 862483.9473684211 361412.1111111111 1278359.6666666667 2111602.5 1564756.1249999998 2111443.4285714286 2150385.3333333335 134019.9090909091 2111560.285714286 2111643.75 133585.33333333334 134012.2 133580.00000000003 1518018.2 133915.6666666667 1452081.6666666665 133894.57142857145 ... ].

If you are loading in those geb-id's from an external source and you are sure there are no floats in that source data, then something in your NetLogo model code must be altering them to that format before you try to use remove-duplicates on them. If you can't discover how the floats are getting in there, posting more of your model's code could help someone find the cause.

Jasper
  • 2,610
  • 14
  • 19