[R] Creating a list of functions

From: Andreas Posch <andreas.posch_at_boku.ac.at>
Date: Thu, 05 Jun 2008 16:50:09 +0200


I've been trying to create a list of function where function[[i]] should actually return the value of i.

trying:

func <- vector("list",2)
i <- 1
while (i <= 2)
{

func[[i]] <- function()
{

i
}
i <- i+1
}

however only returned the last value of i for each function. Any help how to achieve the solution intended would be greatly appreciated.

thanks in advance,

andreas posch



R-help_at_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. Received on Thu 05 Jun 2008 - 16:59:08 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 05 Jun 2008 - 18:30:40 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive