R - Reduce() not working with median

r

Solution

`Reduce` needs a binary operation. `median` is not. What you are computing with `Reduce` is basically something like `median(2, median(5, median(19, 29)))` which is `2` because the second argument to `median` is interpreted as `median`'s second argument 'na.rm'.

Reduce(median, mylist) = median(2, median(5,median(19,29)))
= median(2, median(5,19))
= median(2, 5)
= 2

Problem

I've been doing: ``` mylist<- c(2,5,19,29) Reduce("+", mylist) ``` Result: ``` [1] 55 ``` without any problem. However, then I needed to do a median, so I did: ``` Reduce(median, mylist) ``` which give me: ``` [1] 2 ``` but the answer is supposed to be: ``` median(unlist(hom)) [1] 12 ``` Can someone explain why `Reduce()` is doing this?

Original source