[R] Averaging uneven measurements by time with uneven numbers of measurements

Adele_Thompson at cargill.com Adele_Thompson at cargill.com
Mon May 9 22:41:23 CEST 2011


An easy way to average every 30 minutes is using the aggregate function. First I use the mod (%%) to get times as the next earliest possible 30 min time increment. 

bTime<-  as.POSIXct(c( "2011-04-28 09:02:00 CDT","2011-04-28 09:02:00 CDT","2011-04-28 09:12:00 CDT","2011-04-28 09:14:00 CDT","2011-04-28 09:15:00 CDT","2011-04-28 09:23:00 CDT","2011-04-28 09:45:00 CDT","2011-04-28 09:53:00 CDT","2011-04-28 10:03:00 CDT"))
numTime<-as.numeric(bTime)-21600
Weight<-runif(9)*100
minT<-30
excess<-numTime %% (minT*60)
nTime<-numTime-excess
nDateT<-as.POSIXct(nTime, origin="1970-01-01",tz= "US/Central")
meanw <- aggregate(Weight, list(nDateT), mean, na.rm = TRUE)



-----Original Message-----
From: clint at ecy.wa.gov [mailto:clint at ecy.wa.gov] 
Sent: Thursday, May 05, 2011 03:58 PM
To: Thompson, Adele - Adele_Thompson at cargill.com
Cc: r-help at r-project.org
Subject: Re: [R] Averaging uneven measurements by time with uneven numbers of measurements

In your first request for help you said, "How do I average the 
measurements by every 30 minutes?"  With 25000 readings over three 
days, it looks as if you are getting readings just about every 
second.

Okay, why don't you use the first reading as your initial weight, 
w0.  Then subtract each succeeding reading from that to obtain the 
amount of feed dispensed.  Now plot that value every 30 minutes.

If you are interested in the variation of feed dispensed over a 
half hour interval, that can be easily obtained by accummulating 
those half-hour readings.

-- 
Clint Bowman			INTERNET:	clint at ecy.wa.gov
Air Quality Modeler		INTERNET:	clint at math.utah.edu
Department of Ecology		VOICE:		(360) 407-6815
PO Box 47600			FAX:		(360) 407-7534
Olympia, WA 98504-7600


         USPS:           PO Box 47600, Olympia, WA 98504-7600
         Parcels:        300 Desmond Drive, Lacey, WA 98503-1274


On Thu, 5 May 2011, Schatzi wrote:

> I do not want smoothing as the data should have jumps (it is weight left in
> feeding bunker). I was thinking of maybe using a histogram-like function and
> then averaging that. Not sure if this is possible.
>
> -----
> In theory, practice and theory are the same. In practice, they are not - Albert Einstein
> --
> View this message in context: http://r.789695.n4.nabble.com/Averaging-uneven-measurements-by-time-with-uneven-numbers-of-measurements-tp3499337p3499386.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list