Java Mailing List Archive

http://www.r-help.com/

Home » R Help for Statistical Computing »

Re: [R] sum of list elements

Patrick Burns

2009-07-03

Replies: Find Java Web Hosting

Author LoginPost Reply
My guess is that the original
poster is expecting a matrix
not a scalar. If so, then:

> Reduce('+', a)
   [,1] [,2] [,3]
[1,]   3   0   0
[2,]   0   3   0
[3,]   0   0   3



Patrick Burns
patrick@(protected)
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of "The R Inferno" and "A Guide for the Unwilling S User")


David Winsemius wrote:
>
> 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, CT
>
> ______________________________________________
> R-help@(protected)
> 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.
>

______________________________________________
R-help@(protected)
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.
©2008 r-help.com - Jax Systems, LLC, U.S.A.