Skip to content
Prev 383317 / 398502 Next

calculate row median of every three columns for a dataframe

Some comments on the contributions:
a) for Petr's suggestion, to return the desired structure modify the
statement to
       t(aggregate(t(dfr), list(idx), median)[,-1])
    And, although less readable, can certainly be put in a one-liner
solution by removing the idx definition
        t(aggregate(t(dfr), list((0:(ncol(dfr)-1))%/%3), median)[,-1])
b) to DMcP: "# I'm sure the cognoscenti will have a much more elegant way"
       +1 for elegance (in my view)
c) to Jim: I think your code is instructive. From a style viewpoint I would
recommend against naming a local variable 'stop' :-)

Best,
Eric
On Fri, Apr 17, 2020 at 9:54 AM PIKAL Petr <petr.pikal at precheza.cz> wrote: