[R] Indexing a loop-created list

Alberto Monteiro albmont at centroin.com.br
Thu Oct 19 19:07:49 CEST 2006


Romain Lorrilliere wrote:
>
> try this:
>
> my_list <- NULL
>
> for (i in 1:n)
> 	{for (j in (i+1):m)
> 		{my_list <- c(my_list,list(i_create_a_matrix(i,j)))
> 	}
> }
>
Why it does not work as expected in this case?

  my_list <- NULL

  for (i in 1:10)
    my_list <- c(my_list, function(x) x^i)

  f <- my_list[[2]]
  f(10)

[1] 1e+10

Alberto Monteiro



More information about the R-help mailing list