Skip to content
Prev 237773 / 398500 Next

List or matrix of object

On Oct 12, 2010, at 11:17 AM, Filoche wrote:

            
You should learn a few things  (These should have been explained and  
illustrated as you worked your way through the "An Introduction to R"):

http://cran.r-project.org/doc/manuals/R-intro.pdf

... R is case sensitive so list != List. Changing "List" to "list"  
would help.

... except for the fact that 2x is not a valid expression. Need 2*x

...  and, the "[<-" and "[[<-" operations are different. The use of  
"[[<-" works:

 > f1 <- function(x) sqrt(x%*%x)
 > f2 <- function(x) (2*x+1)
 > L <- list()
 > L[[1]] <- f1
 > L[[2]] <- f2;
 > L

If you want to use "[<-", you will need to give it a valid list object:

 > f1 <- function(x) sqrt(x%*%x)
 > f2 <- function(x) (2*x+1)
 > L <- list()
 > L[1] <- list(f1)
 > L[2] <- list(f2)
 > L

... and drop the use ;'s at the end of lines.