如何在Netlogo和BehaviourSpace中获得更好的csv导出?

时间:2014-10-30 17:04:42

标签: r csv time-series export-to-csv netlogo

我正在阅读以下两个网站about how to export csv data from Netlogo以及如何使用Colin Sheppard time extension及其times series functionality。我有相当多的时间尝试如何使两件事情一起工作,但不知道如何实现它。有人有延长时间的经验,知道如何把它们放在一起吗?

我的想法是使用export-all-plots函数,但有更好的csv输出,以便以后在Gnu R中使用(因为csv中Netlogo数据的标准输出非常奇怪!)。

以下是相关代码段的复制和粘贴:

to write-csv [ #filename #items ]
;; #items is a list of the data (or headers!) to write.
if is-list? #items and not empty? #items
[ file-open #filename
;; quote non-numeric items
set #items map quote #items
;; print the items
;; if only one item, print it.
ifelse length #items = 1 [ file-print first #items ]
[file-print reduce [ (word ?1 "," ?2) ] #items]
;; close-up
file-close
]
end

to-report quote [ #thing ]
ifelse is-number? #thing
[ report #thing ]
[ report (word "\"" #thing "\"") ]
end

和这一个:

extensions [ time ]

globals
[ 
  dt ;time in model
  time-series ;alibi variable
  time-series-file-name ;file name
]

to setup
  ca
  set dt time:anchor-to-ticks (time:create-with-format "1250" "YYYY") 1 "years" ;model start in year 1250
  time:anchor-schedule dt 1 "years" ;anchor time with schedule in model  
  set time-series-file-name "path/to/file.csv" ;set working file for time-series
  reset-ticks
end

to go
  export ;create tables for later use

  tick
end

to export
  set time-series time:ts-create ["item1" "item2"] ;create header of table
  time:ts-add-row time-series [] ;add data to time series
  time:ts-add-row time-series []
  time:ts-write time-series "path/to/file.csv" ;export time-series
end

0 个答案:

没有答案