add support for matrices to ctapply()