I am very new to Netlogo and have been using it to do basic network analysis. I have created a social network made up of 5 different turtle breeds. In order to continue my analysis in another program, I need to create an edge list( a two column list of all the connected nodes in the network). So the first column would have the breed and who number (ex. Actor 1) and the second column would list one of Actor 1's contacts (ex [Actor1, Actor2] [Actor 1, Director5] [Actor1, Producer 1]..........) The output needs to be a txt or csv file so that I can import it easily into EXCEL.
I've tried:
to make-edgelist
file-open "Test.txt"
ask links [file-show both-ends]
ask turtles[file-show who]
file-close
end
The problem is that 'both-ends' only reports the who number, not the breed. I can get the breed by using ask turtles [file-show who] but this appends the identifcation to the end of the edgelist which means a lot of manipulation to get things in the correct format. Does anyone have any suggetsions about how to build the edge list with the breeds+who numbers? I feel like I'm probably missing something simple, but I am new to Netlogo. Thanks!
The csv extension makes this a one-liner. Assuming you have extensions [ csv ] at the top of your code, you can just do:
csv:to-file "test.csv" [ [ (word breed " " who) ] of both-ends ] of links
If you need column titles, you can add them using fput, e.g.:
csv:to-file "test.csv"
fput ["source" "target"]
[ [ (word breed " " who) ] of both-ends ] of links
Note, however, that both-ends is an agentset that will always be accessed in random order, so "source" and "target" are not very meaningful in that case.
If you have directed links and if the direction is important, you can preserve it with this slightly more complicated version:
csv:to-file "test.csv"
fput ["source" "target"]
[ map [ t -> [ (word breed " " who) ] of t ] (list end1 end2) ] of links
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With