Quantcast

Datetime data with missing values

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Datetime data with missing values

Thomas D. Dean-2
I have a set of meter readings, two per day.  On some days, there is
only one reading.  On other days, there are no readings.

I want to compute a moving average of the readings over a window, w,
with the missing values equal to zero.

I did this with a several loops...  I am thinking I was not the first
person to want to do this, so there must be an easier way.

The timestamp in the file is yyyy.mm.dd.hhmm
Here is an example, with the timestamp replaced with integers 0,1,...

Input File:
0 1 61
0 2 64
1 1 52
2 1 65
2 2 93
5 1 54
5 2 82
6 1 64
7 1 82
7 2 83

A = Intermediate array with zero values inserted
0 1 64
0 2 61
1 1 52
1 2 0
2 1 65
2 2 93
3 1 0
3 2 0
4 1 0
4 2 0
5 1 82
5 2 54
6 1 64
6 2 0
7 1 83
7 2 82

## add up the total readings for each day
n = size(A,1)
B = A(1:n-1,3) + A(2:n,3)

I used
wt = ones(7,1)/7
C = conv(B,wt)
D = C(7:96,:)

And, D is the moving average of 7 entries of B
Is there an easy to insert zero for the missing values?  (to go from the
input file to A)

Tom Dean

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Loading...