Home Altering arrays to add/remove entries at each time-step in R
Reply: 0

Altering arrays to add/remove entries at each time-step in R

user1907 Published in June 19, 2018, 4:18 pm

This question, probably has a simple solution but I cannot think of how to do it...

So I have a script as follows:

# ------------------ MODEL SETUP ----------------------------------------# simulation length
t_max <- 50

# arena
arena_x <- 100
arena_y <- 100

# plant parameters

a <- 0.1
b <- 0.1
g <- 1

# list of plant locations and initial sizes
nplants <-dim(plantLocsX)[1]*dim(plantLocsX)[2]


# starting loop 

sep <- 10

# Original matrix
plantLocsX <- matrix(rep(seq(0,arena_x,sep), arena_y/sep),

plantLocsY <- t(plantLocsX)

plantSizes <- matrix(1,nrow=nplants,ncol=1)

# Plot the plants
radius <- sqrt( plantSizes/ pi )
symbols(plantLocsX, plantLocsY, radius, xlim = c(0,100), ylim=c(0,100), inches=0.05, fg = "green", 
        xlab = "x domain (m)", ylab = "y domain (m)", main = "Random Plant Locations", col.main = 51)

# Calculate distances between EACH POSSIBLE PAIR of plants
distances <- matrix(0,nrow=nplants,ncol=nplants)

for (i in 1:nplants){
  for (j in 1:nplants){
    distances[i,j] <- sqrt( (plantLocsX[i]-plantLocsX[j])^2 + (plantLocsY[i]-plantLocsY[j])^2 )

# ------------------ MODEL RUNNING ---------------------------------------

I need to alter the arrays containing plant locations and plant sizes so that at each time step, entries are removed and added (simulating mortality/reproduction, respectively). The "distances" must be updated with plant locations and sizes after each iteration...I can only think of complex ways to do this: destructing and constructing new matrices at each time step to fit the new number of elements but there must be functions to make this simpler....any advice? Many thanks!!

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.344667 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO