You might try something like this: ZVo1 <- with(ZVo, { Year <- substring(as.character(V1), 1, 4) Count <- table(Year) ## for a count of days TFlow <- tapply(V2, Year, sum) ## total flow data.frame(Year=Year, No=Count, TotalFlow=TFlow) })
Bill Venables CSIRO/CMIS Cleveland Laboratories -----Original Message----- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of santosh.ar...@csiro.au Sent: Wednesday, 17 March 2010 3:22 PM To: r-help@r-project.org Subject: [ExternalEmail] [R] Summing daily data for each year Hello there I have a DAILY data set (as shown below) with Date and Streamflow from April 1995 to Aug 2006. I want a yearly sum the streamflow value (for each year - first and last incomplete year). Does anyone know how to do this in R? I have tried everything I could think of, e.g. imported the streamflow data as time series using: flowdata <- ts(ZVo[,2],start = c(1995,4,1), frequency = 7) # perhaps frequency = 365 is the better one and tried to aggregate using aggregate() without success >ZVo V1 V2 1 1995-04-01 0.002766309 2 1995-04-02 0.002402973 3 1995-04-03 0.002254335 4 1995-04-04 0.002221305 5 1995-04-05 0.002180017 6 1995-04-06 0.002031379 7 1995-04-07 0.001957060 8 1995-04-08 0.001940545 9 1995-04-09 0.001924030 10 1995-04-10 0.001783650 . . . 4156 2006-08-16 0.02861272 4157 2006-08-17 0.03652353 4158 2006-08-18 0.05372419 4159 2006-08-19 0.05630058 4160 2006-08-20 0.06274154 4161 2006-08-21 0.06981833 Many thanks Santosh ______________________________________________ R-help@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. ______________________________________________ R-help@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.