我有大量的天气数据。按日期和时间列出。每10分钟就有一个值。从600到1400开始
我想计算两个值的每小时平均值。
nr,date1,time1,val,nr date,time,val2
感谢
{11238, 20120530, 1300, 11290, 20120530, 1300, 141}, {11238, \
20120530, 1310, 11290, 20120530, 1310, 223}, {11238, 20120530, 1320, \
11290, 20120530, 1320, 201}, {11238, 20120530, 1330, 11290, 20120530, \
1330, 275}, {11238, 20120530, 1340, 11290, 20120530, 1340, 371}, \
{11238, 20120530, 1350, 11290, 20120530, 1350, 275}, {11238, \
20120530, 1400, 11290, 20120530, 1400, 238}, {11238, 20120531, 600, \
11290, 20120531, 600, 342}, {11238, 20120531, 610, 11290, 20120531, \
610, 238}, {11238, 20120531, 620, 11290, 20120531, 620, 438}, {11238, \
20120531, 630, 11290, 20120531, 630, 483}, {11238, 20120531, 640, \
11290, 20120531, 640, 498}, {11238, 20120531, 650, 11290, 20120531, \
650, 535}, {11238, 20120531, 700, 11290, 20120531, 700, 527}, {11238, \
20120531, 710, 11290, 20120531, 710, 461}, {11238, 20120531, 720, \
11290, 20120531, 720, 572}, {11238, 20120531, 730, 11290, 20120531, \
730, 624},
答案 0 :(得分:0)
使用您提供的数据格式:{nr, date1, time1, val, nr date, time, val2}
,以下代码输出日期&小时和平均值val和val2。
data = {
{11238, 20120530, 1300, 11290, 20120530, 1300, 141},
{11238, 20120530, 1310, 11290, 20120530, 1310, 223},
{11238, 20120530, 1320, 11290, 20120530, 1320, 201},
{11238, 20120530, 1330, 11290, 20120530, 1330, 275},
{11238, 20120530, 1340, 11290, 20120530, 1340, 371},
{11238, 20120530, 1350, 11290, 20120530, 1350, 275},
{11238, 20120530, 1400, 11290, 20120530, 1400, 238},
{11238, 20120531, 600, 11290, 20120531, 600, 342},
{11238, 20120531, 610, 11290, 20120531, 610, 238},
{11238, 20120531, 620, 11290, 20120531, 620, 438},
{11238, 20120531, 630, 11290, 20120531, 630, 483},
{11238, 20120531, 640, 11290, 20120531, 640, 498},
{11238, 20120531, 650, 11290, 20120531, 650, 535},
{11238, 20120531, 700, 11290, 20120531, 700, 527},
{11238, 20120531, 710, 11290, 20120531, 710, 461},
{11238, 20120531, 720, 11290, 20120531, 720, 572},
{11238, 20120531, 730, 11290, 20120531, 730, 624}};
(* format the time data to hourly timestamps *)
times = (
date = ToString[#2];
hour = StringPadLeft[ToString@Floor[#3/100], 2, "0"];
{date, hour}) & @@@ data;
(* join the timestamps to the data *)
datawithtimes = MapThread[Prepend, {data, times}];
(* gather the data by the timestamps *)
gathered = GatherBy[datawithtimes, First];
(* pick out the data and average *)
{StringJoin[Insert[First@#1, " ", 2], "00"],
N@Mean[#5], N@Mean[#8]} & @@ Transpose[#] & /@ gathered
{{20120530 1300, 11290., 247.667}, {20120530 1400, 11290., 238.}, {20120531 0600, 11290., 422.333}, {20120531 0700, 11290., 546.}}