Re: [R] sum of list elements

2010-03-04 Thread Eleni Christodoulou
Thank you Dimitris! I have 3D arrays of the same dimensions, so Reduce worked... Best, Eleni On Thu, Mar 4, 2010 at 5:13 PM, Dimitris Rizopoulos < d.rizopou...@erasmusmc.nl> wrote: > do these lists contain 3D arrays of the same dimensions? If yes, then you > could use > > Reduce("+", pred.svm[

Re: [R] sum of list elements

2010-03-04 Thread Dimitris Rizopoulos
do these lists contain 3D arrays of the same dimensions? If yes, then you could use Reduce("+", pred.svm[[i]])[1,2,5] otherwise a for-loop will also be clear and efficient, e.g., W <- pred.svm[[i]][[1]][1,2,5] for (j in 2:20) { W <- W + pred.svm[[i]][[j]][1,2,5] } I hope it helps. Best

Re: [R] sum of list elements

2009-07-03 Thread Patrick Burns
My guess is that the original poster is expecting a matrix not a scalar. If so, then: > Reduce('+', a) [,1] [,2] [,3] [1,]300 [2,]030 [3,]003 Patrick Burns patr...@burns-stat.com +44 (0)20 8525 0696 http://www.burns-stat.com (home of "The R Inferno" an

Re: [R] sum of list elements

2009-07-02 Thread David Winsemius
On Jul 2, 2009, at 11:24 PM, David Winsemius wrote: On Jul 2, 2009, at 10:20 PM, Ivo Shterev wrote: a = list(diag(3), diag(3), diag(3)) a = list(diag(3), diag(3), diag(3)) > sum(unlist(a)) [1] 9 Also: > sum(sapply(a,I)) [1] 9 David Winsemius, MD Heritage Laboratories West Hartford,

Re: [R] sum of list elements

2009-07-02 Thread David Winsemius
On Jul 2, 2009, at 10:20 PM, Ivo Shterev wrote: a = list(diag(3), diag(3), diag(3)) a = list(diag(3), diag(3), diag(3)) > sum(unlist(a)) [1] 9 David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https

Re: [R] sum of list elements

2009-07-02 Thread Richard M. Heiberger
I think you are asking for Reduce > Reduce(`+`, a) [,1] [,2] [,3] [1,]300 [2,]030 [3,]003 > You might be asking for do.call with some function's name as its first argument. > do.call("sum", a) [1] 9 > __ R-h