Re: [R] return object from loop inside a function

2011-01-25 Thread Phil Spector
Nicolas - Along with returning a value, the return function passes control back to the caller of the function. So any statement after a return statement will just be ignored. In R the way this is handled is by returning a list. Change return(pop) return(grid.dens) to return(list(pop=pop

[R] return object from loop inside a function

2011-01-25 Thread Nicolas Gutierrez
Hi All, I have a for loop inside the function and I cannot get UUU to give me an updated grid.dens object when I run the function (it does update when I run just the for loop). Here's a simplified version of my function: UUU=function(pop, grid.dens) { for (i in 1:10){ Food=grid.dens[pop$yloc