[R] vertical list sum

Duncan Mackay mackay at northnet.com.au
Sat Oct 30 01:43:04 CEST 2010


Aplogies to the original poster - I got names wrong in a cut and paste


Hi Jorge

I tried your methods for all (which work for complete rows) and then I 
remove the first value of $y and repeated; both fail because of 
the  unequal numbers
The problem is when there are unequal numbers in the rows and trying to 
make a matrix of them.

I was trying some things with Greg's vaules.
x <- list()
x[[1]] <- c(9,5,7,2, 14,  4,  4,  3)
x[[2]] <- c(3,  6, 25,  2, 14,  3,  3 , 4)
x[[3]] <- c(28,  4 ,14,  3, 14,  2  ,4 , 5)
x[4] <- list(28 , 4 ,14 , 3, 14,  2 , 4  )

x.av <- list()
for(j in seq_along(1:max(sapply(x,length))) ) x.av[j] <- 
mean(sapply(x,"[",j),na.rm=T)
unlist(x.av) # if you want a vector

which Greg may have used first

Regards

Duncan
______________________________________________
>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.



More information about the R-help mailing list