Hello, I have a list like the following:
tree<-list(); tree[[1]]$node<-list(); tree[[2]]$node<-list(); tree[[1]]$node$values <- 1:10 tree[[2]]$node$values <- 1:10 After building the list I have to generate the mean of all "values" elements with equal indices. Until now I use something like that: for(i in seq(along=tree[[1]]$node$values)) { print(mean(tree[[1]]$node$values[i], tree[[2]]$node$values[i])); } [1] 1 [1] 2 ... [1] 10 (I don't need a sapply(tree, function(x)mean(x$node$values));) But I want to do a "sapply" over the "values" vectors. Sadly this don't work: sapply(tree[1:2]$node$values, function(x)mean(x)); Is there another solution? Kind regards, Sebastian ______________________________________________ R-help@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.