Hi!
You don’t show how you are using remove item, so I’m note sure where the error is. I think maybe you’ve got replace and remove switched. Could you please say exactly what you mean by “it doesn’t work?”
Do you really want to remove the value, or just replace it with a blank value?
It helps in these situations to avoid excess brevity… break it all down :
Let old-row item 1 historic-data
Let new-row remove-item 2 old-row
Set historic-data replace-item 1 historic-data new-row
Then put it back together:
Set historic-data replace-item 1 historic-data (remove-item 2 (item 1 historic-data)
I am not a fan of working with lists of lists, especially if they have to change.
It’s sometimes useful to use a list or set of “data-row” turtles. These turtles own variables that are the columns of your table.
So to get the row you use
Let row item 2 historic-data
Then replace a value
Ask row [ set fruit “apple” ]
Removing a column isn’t really a thing, but you can make it blank (“”) or 0 or false or even use “nobody” as a stand-in for “null”
And you can query your table.
IF “history” is an agentset of data-row turtles, an SQL-style like
SELECT TOP 1 FRUIT FROM HISTORY WHERE TIMESTEP = ‘1234’
Becomes
[ fruit ] of ( one-of ( history with [ timestep = “1234” ] ) )
Somewhere in the deep history of this list or it’s predecessor is a long discussion of this technique.
~~James
Hello,
I can't succeed in using the `remove-item` command inside lists of list.
For example
set my-list [ ["cereal" "cereal" 0.8] ["cereal" "fruit" 0.002] ["cereal" "forage" 0.06] ]
how can I remove the item 2 of the second list (value 0.002) ?
I tried to use `remove-item` command the same way I use replace-item (which works) but it doesn't work :
set historic-data replace-item 1 historic-data (replace-item 2 item 1 historic-data ("apple"))
Thanks, Sarah