Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Netlogo 加载重复项/合并变量_Netlogo - Fatal编程技术网

Netlogo 加载重复项/合并变量

Netlogo 加载重复项/合并变量,netlogo,Netlogo,我正在加载包含大量重复数据的动物数据,我正试图将这些数据合并到一个代表单个动物的代理中。csv文件如下所示: 动物ID-组ID 1-A 2-A 3-A 4-A 1-B 2-B 在这个例子中,我希望生产出4种独特的动物制剂,它们有一个与它们相关的群体列表。动物1的名单是[A,B],而动物4的名单只是[A] 到目前为止,我正在使用以下方式加载csv: csv:from-row file-read-line create-animal 1 [ set Animal-ID i

我正在加载包含大量重复数据的动物数据,我正试图将这些数据合并到一个代表单个动物的代理中。csv文件如下所示:

动物ID-组ID

1-A

2-A

3-A

4-A

1-B

2-B

在这个例子中,我希望生产出4种独特的动物制剂,它们有一个与它们相关的群体列表。动物1的名单是[A,B],而动物4的名单只是[A]

到目前为止,我正在使用以下方式加载csv:

   csv:from-row file-read-line
   create-animal 1 [
        set Animal-ID item 0 data
        set group-ID item 1 data]


Which produces 6 animals with one group id each.

But how should I cull the duplicate animals?


如果您的csv看起来像:

id, group
1,A
2,A
3,A
4,A
1,B
2,B
您可以将csv作为列表加载,提取唯一的动物,然后使用唯一的动物ID过滤原始列表,以获取该动物所属的唯一组:

extensions [ csv ]

breed [ animals animal ]

animals-own [ animal-id group-id ]

to setup 
  ca
  
  ; Load animal data as a list of lists, drop the headers
  let animalData but-first csv:from-file "exampleAnimals.csv"
  print animalData
  
  ; Get the unique animal ids
  let animalIds remove-duplicates map [ i -> first i ] animalData
  print animalIds
  
  foreach animalIds [ id ->
    create-animals 1 [
      
      ; Set the id
      set animal-id id
      
      ; Filter the animal data by the id of the current animal
      let filtered filter [ row -> first row = id ] animalData
         
      ; Map to pull the group id as a list and assign to the animal
      set group-id map [ i -> last i ] filtered
      
      fd 1
    ]    
  ]
  reset-ticks
end
希望有帮助


除了组id之外,我正在尝试加载更多的信息列,并将它们作为更多的自有变量分配给动物id。您能否澄清您如何选择第二个(与第三个、第四个等)是用于提取数据的?这种安排似乎总是拉信息的最后一栏。这是你在短语[i->LAST i]中使用LAST的地方吗?我可以在第3项或类似项中交换以选择其他列吗?@Andrewioak是的,完全正确!将
set group id map[i->last i]filtered
更改为
set group id map[i->item 3 i]filtered
以选择所需的列。