Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

netlogo convert string to numbers within nested lists

Tags:

netlogo

I am transferring between NetLogo and igraph (in R). Some of the information returned from igraph is 2-level nested lists of strings. Typical example looks like:

[ ["1" "2" "3"] ["4"] ]

I want to convert the internal strings into numbers, while retaining the list structure. So the example would become:

[ [1 2 3] [4] ]

I am guessing I need a combination of map and read-from-string (and perhaps other list manipulation like lput and foreach due to the nesting), but I just can't make it work.

Any ideas?

like image 963
JenB Avatar asked Jan 06 '23 06:01

JenB


1 Answers

Essentially, map each list to a mapped list with only int values. Try the following:

show map [ map [ read-from-string ? ] ?] [ ["1" "2" "3"] ["4"] ]
like image 198
mattsap Avatar answered Mar 06 '23 00:03

mattsap