foldr1 | R Documentation |
A right fold without the need for a neutral element. Does not work with empty lists.
foldr1(f, xs)
f |
|
xs |
There is a |
# We generate some random numbers. numbers <- rnorm(10) # The sum is easiest computed with the `sum` function: sum(numbers) # If we wanted to implement `sum` ourselves, we can use a right fold to do # so: Reduce(`+`, numbers, 0.0) # With this new function we do not need a neutral element any more, but give # up the possibility to fold empty lists. foldr1(`+`, numbers)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.