How about something like this?

jonas <- data.frame(time = seq(100, 216000, by = 150), crobs = rnorm(1440))
head(jonas)

jonas$halfhour <- cut(jonas$time, breaks = seq(from = 0, to = 216000, by =
1800))
head(jonas)

tapply(jonas$crobs, INDEX = list(jonas$halfhour), FUN = mean)
# or
aggregate(crobs ~ halfhour, data = jonas, FUN = mean)
#or
by(data = jonas, INDICES = jonas$halfhour, FUN = function(x) mean(x$crobs))


Cheers,
Roman



On Mon, Apr 22, 2013 at 12:13 PM, Jonas Steenholdt Sørensen <
jonas.steenho...@gmail.com> wrote:

> > Hi everbody
> >
> > I'm working on my bachelor thesis on clearance rate for mussel and need
> some help R. First have a look at the DF
> >
> > Time            CRobs
> > 150              4.6589
> > 300              3.9685
> > 450              4.0124
> > ......               ...........
> > 216000       1.0281
> >
> > These data is just made up, but is give some idea of the DF. I want to
> simplify my data and instead of having 144 rows of clearance rate, I want
> to look at the average within haft an hour. Like this:
> >
> > Time       avgCRobs
> > 1800         =average from 150-1800
> > 3600         =average from 1800-3600
> > .....
> > 21600       =average from 19800-21600
> >
> > I have talk to one of my friend, that working mainly on C++ and he try
> with a loop function without any help and other of my college and friends
> from my studies couldn't help either. So I'm hoping there is one that could
> lead my on the right direction.
>
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>



-- 
In God we trust, all others bring data.

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-ecology mailing list
R-sig-ecology@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology

Reply via email to