# Finding center of mass in a hydrologic time series Classic List Threaded 6 messages Open this post in threaded view
|

## Finding center of mass in a hydrologic time series

 The small bit of script below is an example of what I'm attempting to do - find the day on which the 'center of mass' occurs.  In case that is the wrong term, I'd like to know the day that essentially cuts the area under the curve in to two equal parts: set.seed(4004) Date <- seq(as.Date('2000-09-01'), as.Date('2000-09-30'), by='day') hyd <- ((100*(sin(seq(0.5,4.5,length.out=30))+10) + seq(45,1,length.out=30)) + rnorm(30)*8) - 800 # View the example curve plot(Date, hyd, las=1) # By trial-and-error, the day on which the center of mass occurs is the 11th day: # Add up the area under the curve for the first 11 days and compare # with the last 19 days: sum(hyd[1:11]) # 3546.364 sum(hyd[12:30]) # 3947.553 # Add up the area under the curve for the first 12 days and compare # with the last 18 days: sum(hyd[1:12]) # 3875.753 sum(hyd[13:30]) # 3618.164 By day 12, the halfway point has already been passed, so the answer that would be returned would be: Date # "2000-09-11" For the larger problem, it'd be handy if the proposed function could process a multi-year time series (a runoff hydrograph) and return the day of the center of mass for each year in the time series. I appreciate any pointers...Eric         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Finding center of mass in a hydrologic time series

 Hi Eric, How about match( TRUE, cumsum(hyd/sum(hyd)) > .5 ) - 1 HTH, Eric On Sat, Dec 16, 2017 at 3:18 PM, Morway, Eric <[hidden email]> wrote: > The small bit of script below is an example of what I'm attempting to do - > find the day on which the 'center of mass' occurs.  In case that is the > wrong term, I'd like to know the day that essentially cuts the area under > the curve in to two equal parts: > > set.seed(4004) > Date <- seq(as.Date('2000-09-01'), as.Date('2000-09-30'), by='day') > hyd <- ((100*(sin(seq(0.5,4.5,length.out=30))+10) + > seq(45,1,length.out=30)) + rnorm(30)*8) - 800 > > # View the example curve > plot(Date, hyd, las=1) > > # By trial-and-error, the day on which the center of mass occurs is the > 11th day: > # Add up the area under the curve for the first 11 days and compare > # with the last 19 days: > > sum(hyd[1:11]) > # 3546.364 > sum(hyd[12:30]) > # 3947.553 > > # Add up the area under the curve for the first 12 days and compare > # with the last 18 days: > > sum(hyd[1:12]) > # 3875.753 > sum(hyd[13:30]) > # 3618.164 > > By day 12, the halfway point has already been passed, so the answer that > would be returned would be: > > Date > # "2000-09-11" > > For the larger problem, it'd be handy if the proposed function could > process a multi-year time series (a runoff hydrograph) and return the day > of the center of mass for each year in the time series. > > I appreciate any pointers...Eric > >         [[alternative HTML version deleted]] > > ______________________________________________ > [hidden email] mailing list -- To UNSUBSCRIBE and more, see > 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. >         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Finding center of mass in a hydrologic time series

Open this post in threaded view
|