Skip to content
Back to formatted view

Raw Message

Message-ID: <CAMXbmUQNgopNTZR0QccKQQcJ++9dOAy9QTqro0kwn8NqmYYGPw@mail.gmail.com>
Date: 2012-05-09T19:46:34Z
From: Robert Latest
Subject: How to apply functions across columns?
In-Reply-To: <CAAmySGPHrxx-_onb-fR1v3a6w3L9J3JE1fOMwFOJt+FTueE7KA@mail.gmail.com>

On Wed, May 9, 2012 at 4:19 PM, R. Michael Weylandt
<michael.weylandt at gmail.com> wrote:
> Good reproducible example ;-)
>
> Easiest is probably just:
>
> cbind(tencor, ThisRowMean = ?rowMeans(tencor[, 4:8]))

Actually, after frying my brain on tapply() and sapply() I found that
just plain apply() does what I need:

tencor$mean <- apply(tencor[4:8], 1, FUN=mean)

This way I'm also not tied to just mean() as aggregator but can use
any homemade function (this would have been my followup question had I
followed your advice ;-)

Thanks!
robert