[R] summing 15 minute precip data to daily

Joshua Wiley jwiley.psych at gmail.com
Thu Feb 17 21:04:59 CET 2011


Hi Janet,

One relatively simple way would be to transofrm the data into a 96 x
Ndays matrix and use colSums().  Of course, lets say on one day, the
measurement tool had technical difficulties and missed two
observations, then you only have 94 observations for that day, you
will need a fancier solution that deals with time not number of
observations.  Below is an example.

Cheers,

Josh


## Imaginary precipitation data for 7 days
set.seed(10)
x <- rnorm(96*7, 1, .1)
## An alternate way you may have the data stored
xalt <- data.frame(precip = x)

## Assuming _no_ missing observations
colSums(matrix(x, nrow = 96))

## alternate version
colSums(matrix(xalt$precip, nrow = 96))


On Thu, Feb 17, 2011 at 11:56 AM, Janet Choate <jsc.eco at gmail.com> wrote:
> Hi all,
> i'm sure there is an easy way to do this, but i'm stumped, so any help would
> be appreciated.
>
> i have a single column of data for precipitation every 15 minutes over a
> year.  i want to sum the precip to daily data.
> so the first 96 records = the first day, the second 96 records = the second
> day, and so on....
> is there a way to write a for loop that would sum the data to daily, and
> write each value to a second object so i end up with a file of daily precip?
>
> thanx,
> Janet
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/



More information about the R-help mailing list