是否可以在 NetLogo 6.2 中将 4 列列表转换为 4 列 table?

Is it possible to transform a 4-column list into a 4-column table in NetLogo 6.2?

我有一个代码可以生成如下列表形式的输出:

我希望输出如下所示:

是否可以在 netlogo 6.2 中执行此操作?

是的,但是- 我认为您的方法可能会使您的目标过于复杂。作为替代方案,考虑像这样的玩具模型:

extensions [ csv ]
turtles-own [ my_xcor my_ycor ]
globals [ output_list ]

to setup
  ca
  set output_list [["who" "my_xcor" "my_ycor" "tick"]]
  crt 2
  reset-ticks
end

to go 
  ask turtles [
    rt random 90 - 45
    fd 1
    set my_xcor pxcor
    set my_ycor pycor
    set output_list lput ( list who my_xcor my_ycor ticks ) output_list
  ]
  tick
end

to example-experiment 
  setup
  repeat 5 [ go ]
  csv:to-file "example_output.csv" output_list
end

如果您 运行 example-experiment 过程,它将导出一个类似于以下内容的文件:


如果您必须走这条路,并且您不能用 R 之类的东西解析原始 csv 输出,这可能会更简单,请考虑以下不同的设置:

extensions [csv]

globals [ output-list ]

turtles-own [ xcor-list ycor-list tick-list]

to setup
  ca
  reset-ticks
  set output-list [["who" "my_xcor" "my_ycor" "tick"]]
  crt 2 [
    set xcor-list []
    set ycor-list []
    set tick-list []
  ]
  repeat 5 [
    ask turtles [
      rt random 90 - 45
      fd 1
      set xcor-list lput pxcor xcor-list
      set ycor-list lput pycor ycor-list
      set tick-list lput ticks tick-list
    ]
  ]
end

现在,想法是在导出之前遍历海龟并将它们的每个跟踪列表折叠成一个列表列表:

to export-long 
  ; Iterate over each turtle to extract their listed values
  foreach sort turtles [
    t ->
    ; Pull values / lists from each turtle in order
    let cur-x-list [xcor-list] of t
    let cur-y-list [ycor-list] of t
    let cur-tick-list [tick-list] of t
    let cur-who-list n-values ( length cur-x-list ) [[who] of t]
    
    ( foreach cur-who-list cur-x-list cur-y-list cur-tick-list  [
      [ a b c d ] ->
      let to-append ( list a b c d )
      set output-list lput to-append output-list
    ]) 
  ]
  
  ; Export the list to csv
  csv:to-file "list_example_output.csv" output-list
end

结果: