[R] Question about Reduce
Dimitri Liakhovitski
dimitri.liakhovitski at gmail.com
Fri Oct 1 16:48:08 CEST 2010
Hello!
In the example below the Reduce() function by default assigns "a" to
be the last accumulated value and "b" to be the current value in "x".
I could not find this documented anywhere as the default settings for
the Reduce() function. Does any sort of documentation for this
behavior exist?
x <- c(0,0,0,0,0,1,0,0,0,5,0,0,0,7,0,0,0,8,5,10)
Reduce(function(a,b) b + (a * 0.5),x,accumulate=T,init=0)
[1] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
1.0000000 0.5000000 0.2500000
[10] 0.1250000 5.0625000 2.5312500 1.2656250 0.6328125 7.3164062
3.6582031 1.8291016 0.9145508
[19] 8.4572754 9.2286377 14.6143188
Thanks a lot!
--
Dimitri Liakhovitski
Ninah Consulting
www.ninah.com
More information about the R-help
mailing list