Tried to fix median calc via plyr, but that did not work for me