Skip to content

Effeciently sum 3d table

26 messages · Petr Savicky, Greg Snow, Bert Gunter +3 more

Messages 26–26 of 26

#
Thanks again, Greg. I must have gotten up on the wrong side of the keyboard
this morning and been having a spate of dim insight. What you've said here
makes things clearer.

DAV


-----Original Message-----
From: Greg Snow [mailto:538280 at gmail.com] 
Sent: Monday, April 16, 2012 5:42 PM
To: David A Vavra
Cc: r-help at r-project.org
Subject: Re: [R] Effeciently sum 3d table

Here is a simple example:
[1] TRUE

Basically what Reduce does is it first applies the function (`+` in
this case) to the 1st 2 elements of mylist, then applies it to that
result and the 3rd element, then that result and the 4th element (and
would continue on if mylist had more than 4 elements).  It is
basically a way to create functions like sum from functions like `+`
which only work on 2 objects at a time.

Another way to see what it is doing is to run something like:
The Reduce function will probably not be any faster than a really well
written loop, but will probably be faster (both to write the command
and to run) than a poorly designed naive loop application.
On Mon, Apr 16, 2012 at 12:52 PM, David A Vavra <davavra at verizon.net> wrote:
saying
There's
wrote:
value.