i have an array like this:
["2011-06-16 16:37:20",23.2],
["2011-06-21 16:37:20",35.6],
["2011-06-26 16:37:20",41.8],
["2011-07-01 16:37:20",25],
["2011-07-06 16:37:20",22.8],
["2011-07-11 16:37:20",36.4],
["2011-07-16 16:37:20",34],
["2011-07-21 16:37:20",20]
[...]
Format: [$date,count]
Now i need to add an 3rd an 4th value to every array element, which is an average of N counts before or after.
Example if N=3
the 3rd value should be the average of the 3 count-values before and the 4th value should be the average of the 3 count-values after the current array element. The Result look like that:
["2011-06-16 16:37:20",23.2, null, 34.13],
["2011-06-21 16:37:20",35.6, null, 29.86],
["2011-06-26 16:37:20",41.8, null, 28.06],
["2011-07-01 16:37:20",25, 33.53, 31.06],
["2011-07-06 16:37:20",22.8, 34.13, 30.13],
["2011-07-11 16:37:20",36.4, 29.86, null],
["2011-07-16 16:37:20",34, 28.06, null],
["2011-07-21 16:37:20",20, 31,06, null]
the null value is nothing more then an placeholder for values which cant be calculated, because there are not enough values to calculate an average of N counts.
It's also possible to place the average of all available counts, like "24.4"(23.2+35.6)/2 for the 3rd line instead of null:
["2011-06-26 16:37:20",41.8, 24.4, 28.06],
I have no idea, ho to build code for that.
Hope for an hint or assistance.
Thank you.
//Update: sorry, but..please: could somebody explain me, why 2 people votes this question down? I don't know why. That's not fair - talk to me, if i did an mistake? Sorry for that!