Message-ID: <4EC65CE7.7080502@knmi.nl>
Date: 2011-11-18T13:25:59Z
From: Paul Hiemstra
Subject: Apply functions along "layers" of a data matrix
In-Reply-To: <4EC65814.5080505@gmail.com>
On 11/18/2011 01:05 PM, saschaview at gmail.com wrote:
> daf <- data.frame(
> 'id' = rep(1:5, 3),
> matrix(1:60, nrow=15, dimnames=list( NULL, paste('v', 1:4, sep='') )),
> rep = rep(1:3, each=5)
> )
Hi,
This seems like a job for plyr!
library(plyr)
ddply(daf, .(rep), summarise, mn = mean(v1))
hope this helps,
Paul
--
Paul Hiemstra, Ph.D.
Global Climate Division
Royal Netherlands Meteorological Institute (KNMI)
Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39
P.O. Box 201 | 3730 AE | De Bilt
tel: +31 30 2206 494
http://intamap.geo.uu.nl/~paul
http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770