Closed RichardShea closed 4 years ago
Hi Richard,
To efficiently represent the turtles in R, we chose to create the agentMatrix object to store the turtles and their characteristics/variables. This object was created to be updated in the fastest way and therefore it looks like a matrix with each row being an individual and each column being a characteristic. Unfortunately, you cannot assign a list (or anything else other than a single value) to an individual's characteristic.
To hold several clock values, the only way would be to create several columns in the agentMatrix clock1, clock2, clock3, clock4, etc. and then assign to each one one value.
The problem is if you want to assign an unknown or variable number of values (or even a very large number of values). One possible way would be to keep the vector or list of values (i.e., clock) separated from the t1 object and retrieve clock values from the vector/list when needed instead than retrieving them from the t1 object. I don't know if this can work for you.
Unfortunately, the way the agentMatrix is built, there is no way for now to store multiple values under one characteristic. I thought about it and I don't know how I could modify the agentMatrix to allow it. I don't think it would be possible.
Thanks for your interest. I hope my explanations were clear and that you can work around your issue. Don't hesitate to contact me again if you have questions!
Sarah Bauduin
Hi, I'm replicating the Firefly model from NetLogo in NetLogoR package.
In NetLogo, we can set a turtle's variable as list of random numbers.
My code the gives the error is :
Set turtles clock
clock <- 0 t1 <- turtlesOwn(turtles = t1, tVar = "Clock", tVal = clock)
update clock for first turtle
clock <- runif(10) t1 <- NLset(turtles = t1, agents = turtle(t1, who = 0), var = "Clock", val = clock)
I then get the following error:
Error in turtles@.Data[, var] <- as.numeric(val) : number of items to replace is not a multiple of replacement length
Reading the NetLogoR.pdf :
Am I doing something wrong? Can we only set one numerical value per turtle variable???
Thank you,
Richard Shea rshea5@jhu.edu