Hi All,

Trying to figure out the way to create a vector of values inside a loop

I have a matrix pop:

  Id yloc xloc weight
1
2
.

and spatial grid grid.dens with "coordinates" (x=xloc,y=yloc)

I want to create two more vectors: Food and Consumed inside the loop and add those to pop so:

  Id yloc xloc weight Food Consumed
1
2
.

I'm trying something like this but not getting what I want.

nagent=100
Food=list()
Consumed=list()

ind=function(pop, grid.dens){

for (i in 1:nagent){

Food[[i]]=grid.dens[pop$yloc[i],pop$xloc[i]]

Consumed[[i]]=pop$weight[i]*0.8*(Food[[i]]/(0.2+Food[[i]]))

Food[[i]]=Food[[i]]-Consumed[[i]]

}

Any thoughts?

THANKS!!!

Nico

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to