[R] x y averaging

Randy Zelick zelickr at pdx.edu
Wed Jun 7 05:55:28 CEST 2006


Hello,

I am trying to average a number of data sets where the x vector contains 
times and the Y data are instrument readings. The vectors all have 
different numbers of values, but many X time values match. For example:

A fragment of the first data set:

x vect    value
14:56:10  0.325
14:62:11  0.111
14:68:11  0.214
.
.
.
this can go on for 100's of values, spaced by 6 minutes, but there can be 
gaps too, like:

16:05:18  0.245
16:11:09  0.266
16:17:05  0.271
16:33:00  0.304
16:39:05  0.300


A fragment of the second data set:

15:59:08  0.255
16:05:44  0.281
16:11:25  0.249
16:17:39  0.238
16:23:51  0.288


...and the result I am looking for is a new vector that looks like this:

14:56:10  0.325
14:62:11  0.111
14:68:11  0.214
.
.
.
15:59:08  0.255
16:05:18  0.2630  * matches, so average
16:11:09  0.2575  * matches, so average
16:17:05  0.2545  * matches, so average
16:33:00  0.304
16:39:05  0.300


The times values in the new X vector are properly interleaved taking data 
across the datasets, but when there is a match the Y values are averaged. 
Note that the seconds don't matter.

I am using R Version 2.2.1 on a PC

Thanks for thinking about it,

=Randy=

R. Zelick				email: zelickr at pdx.edu
Department of Biology			voice: 503-725-3086
Portland State University		fax:   503-725-3888

mailing:
P.O. Box 751
Portland, OR 97207

shipping:
1719 SW 10th Ave, Room 246
Portland, OR 97201



More information about the R-help mailing list