'iterate over function and store all results

So let's say I have a function func and I want to to call this function for a sequence of numbers.

func <- function (N) {
  result <- N + 3
  return(result)
}

NList <- seq(1:100)
abc <- numeric(100)
for (i in NList) {
  abc[i] <- func(i)
}

abc`

Now this works beautifully if the number is relatively small and the function is a simple one. but with large numbers and a more complex funciton, it takes ages. It is important to store all results of the funciton calls so I can use them in a plot against the number of function calls. Is there a more efficient way to do this?

Thank you!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source