-6
$\begingroup$

data={{{2006, 1, 1, 0, 0, 0.}, 326.492, {2006, 1, 1, 3, 0, 0.}, 323.08, {2006, 1, 1, 6, 0, 0.}, 314.223, {2006, 1, 1, 9, 0, 0.}, 314.361, {2006, 1, 1, 12, 0, 0.}, 322.048, {2006, 1, 1, 15, 0, 0.}, 323.954, {2006, 1, 1, 18, 0, 0.}, 329.694, {2006, 1, 1, 21, 0, 0.}, 328.151, {2006, 1, 2, 0, 0, 0.}, 330.2, {2006, 1, 2, 3, 0, 0.}, 326.028, {2006, 1, 2, 6, 0, 0.}, 321.627, {2006, 1, 2, 9, 0, 0.}, 322.35, {2006, 1, 2, 12, 0, 0.}, 324.12, {2006, 1, 2, 15, 0, 0.}, 326.305, {2006, 1, 2, 18, 0, 0.}, 326.472, {2006, 1, 2, 21, 0, 0.}, 328.135, {2006, 1, 3, 0, 0, 0.}, 329.194, {2006, 1, 3, 3, 0, 0.}, 327.481, {2006, 1, 3, 6, 0, 0.}, 326.669, {2006, 1, 3, 9, 0, 0.}, 328.192, {2006, 1, 3, 12, 0, 0.}, 333.164, {2006, 1, 3, 15, 0, 0.}, 335.645, {2006, 1, 3, 18, 0, 0.}, 336.476, {2006, 1, 3, 21, 0, 0.}, 338.306, {2006, 1, 4, 0, 0, 0.}, 339.458, {2006, 1, 4, 3, 0, 0.}, 334.536, {2006, 1, 4, 6, 0, 0.}, 328.724, {2006, 1, 4, 9, 0, 0.}, 328.655, {2006, 1, 4, 12, 0, 0.}, 332.485, {2006, 1, 4, 15, 0, 0.}, 335.088, {2006, 1, 4, 18, 0, 0.}, 337.114, {2006, 1, 4, 21, 0, 0.}, 337.366, {2006, 1, 5, 0, 0, 0.}, 338.779, {2006, 1, 5, 3, 0, 0.}, 335.708, {2006, 1, 5, 6, 0, 0.}, 326.423, {2006, 1, 5, 9, 0, 0.}, 325.267, {2006, 1, 5, 12, 0, 0.}, 329.921, {2006, 1, 5, 15, 0, 0.}, 332.107, {2006, 1, 5, 18, 0, 0.}, 333.599, {2006, 1, 5, 21, 0, 0.}, 333.82, {2006, 1, 6, 0, 0, 0.}, 334.48, {2006, 1, 6, 3, 0, 0.}, 330.553, {2006, 1, 6, 6, 0, 0.}, 321.303, {2006, 1, 6, 9, 0, 0.}, 320.164, {2006, 1, 6, 12, 0, 0.}, 325.976, {2006, 1, 6, 15, 0, 0.}, 326.513, {2006, 1, 6, 18, 0, 0.}, 329.622, {2006, 1, 6, 21, 0, 0.}, 330.697, {2006, 1, 7, 0, 0, 0.}, 331.182, {2006, 1, 7, 3, 0, 0.}, 326.039, {2006, 1, 7, 6, 0, 0.}, 318.691, {2006, 1, 7, 9, 0, 0.}, 318.71, {2006, 1, 7, 12, 0, 0.}, 324.686, {2006, 1, 7, 15, 0, 0.}, 326.495, {2006, 1, 7, 18, 0, 0.}, 328.6, {2006, 1, 7, 21, 0, 0.}, 329.187, {2006, 1, 8, 0, 0, 0.}, 331.104, {2006, 1, 8, 3, 0, 0.}, 326.403, {2006, 1, 8, 6, 0, 0.}, 319.914, {2006, 1, 8, 9, 0, 0.}, 319.141, {2006, 1, 8, 12, 0, 0.}, 320.443, {2006, 1, 8, 15, 0, 0.}, 323.578, {2006, 1, 8, 18, 0, 0.}, 326.673, {2006, 1, 8, 21, 0, 0.}, 328.346, {2006, 1, 9, 0, 0, 0.}, 330.256, {2006, 1, 9, 3, 0, 0.}, 328.464, {2006, 1, 9, 6, 0, 0.}, 319.662, {2006, 1, 9, 9, 0, 0.}, 320.738, {2006, 1, 9, 12, 0, 0.}, 325.786, {2006, 1, 9, 15, 0, 0.}, 334.061, {2006, 1, 9, 18, 0, 0.}, 329.304, {2006, 1, 9, 21, 0, 0.}, 328.593, {2006, 1, 10, 0, 0, 0.}, 326.963, {2006, 1, 10, 3, 0, 0.}, 322.941, {2006, 1, 10, 6, 0, 0.}, 313.76, {2006, 1, 10, 9, 0, 0.}, 312.741, {2006, 1, 10, 12, 0, 0.}, 314.636, {2006, 1, 10, 15, 0, 0.}, 316.681, {2006, 1, 10, 18, 0, 0.}, 318.124, {2006, 1, 10, 21, 0, 0.}, 319.609, {2006, 1, 11, 0, 0, 0.}, 321.136, {2006, 1, 11, 3, 0, 0.}, 319.109, {2006, 1, 11, 6, 0, 0.}, 314.94, {2006, 1, 11, 9, 0, 0.}, 314.124, {2006, 1, 11, 12, 0, 0.}, 314.691, {2006, 1, 11, 15, 0, 0.}, 315.855, {2006, 1, 11, 18, 0, 0.}, 316.476, {2006, 1, 11, 21, 0, 0.}, 317.422, {2006, 1, 12, 0, 0, 0.}, 320.974, {2006, 1, 12, 3, 0, 0.}, 320.894, {2006, 1, 12, 6, 0, 0.}, 317.82, {2006, 1, 12, 9, 0, 0.}, 320.186, {2006, 1, 12, 12, 0, 0.}, 323.888, {2006, 1, 12, 15, 0, 0.}, 323.839, {2006, 1, 12, 18, 0, 0.}, 323.132, {2006, 1, 12, 21, 0, 0.}, 326.405, {2006, 1, 13, 0, 0, 0.}, 329.781, {2006, 1, 13, 3, 0, 0.}, 326.373, {2006, 1, 13, 6, 0, 0.}, 319.098, {2006, 1, 13, 9, 0, 0.}, 319.103, {2006, 1, 13, 12, 0, 0.}, 323.52, {2006, 1, 13, 15, 0, 0.}, 327.681, {2006, 1, 13, 18, 0, 0.}, 318.762, {2006, 1, 13, 21, 0, 0.}, 319.757, {2006, 1, 14, 0, 0, 0.}, 317.946, {2006, 1, 14, 3, 0, 0.}, 318.51, {2006, 1, 14, 6, 0, 0.}, 318.662, {2006, 1, 14, 9, 0, 0.}, 318.798, {2006, 1, 14, 12, 0, 0.}, 323.251, {2006, 1, 14, 15, 0, 0.}, 327.992, {2006, 1, 14, 18, 0, 0.}, 336.417, {2006, 1, 14, 21, 0, 0.}, 329.91, {2006, 1, 15, 0, 0, 0.}, 330.959, {2006, 1, 15, 3, 0, 0.}, 325.356, {2006, 1, 15, 6, 0, 0.}, 320.116, {2006, 1, 15, 9, 0, 0.}, 318.204, {2006, 1, 15, 12, 0, 0.}, 324.788, {2006, 1, 15, 15, 0, 0.}, 326.794, {2006, 1, 15, 18, 0, 0.}, 326.043, {2006, 1, 15, 21, 0, 0.}, 328.213, {2006, 1, 16, 0, 0, 0.}, 329.418, {2006, 1, 16, 3, 0, 0.}, 325.934, {2006, 1, 16, 6, 0, 0.}, 320.338, {2006, 1, 16, 9, 0, 0.}, 319.361, {2006, 1, 16, 12, 0, 0.}, 325.494, {2006, 1, 16, 15, 0, 0.}, 327.167, {2006, 1, 16, 18, 0, 0.}, 328.414, {2006, 1, 16, 21, 0, 0.}, 329.696, {2006, 1, 17, 0, 0, 0.}, 330.53, {2006, 1, 17, 3, 0, 0.}, 326.143, {2006, 1, 17, 6, 0, 0.}, 320.913, {2006, 1, 17, 9, 0, 0.}, 320.573, {2006, 1, 17, 12, 0, 0.}, 325.655, {2006, 1, 17, 15, 0, 0.}, 328.056, {2006, 1, 17, 18, 0, 0.}, 330.983, {2006, 1, 17, 21, 0, 0.}, 329.368, {2006, 1, 18, 0, 0, 0.}, 327.041, {2006, 1, 18, 3, 0, 0.}, 324.301, {2006, 1, 18, 6, 0, 0.}, 319.651, {2006, 1, 18, 9, 0, 0.}, 320.206, {2006, 1, 18, 12, 0, 0.}, 326.33, {2006, 1, 18, 15, 0, 0.}, 328.402, {2006, 1, 18, 18, 0, 0.}, 333.758, {2006, 1, 18, 21, 0, 0.}, 330.415, {2006, 1, 19, 0, 0, 0.}, 331.269, {2006, 1, 19, 3, 0, 0.}, 325.665, {2006, 1, 19, 6, 0, 0.}, 320.229, {2006, 1, 19, 9, 0, 0.}, 319.886, {2006, 1, 19, 12, 0, 0.}, 325.75, {2006, 1, 19, 15, 0, 0.}, 326.794, {2006, 1, 19, 18, 0, 0.}, 327.799, {2006, 1, 19, 21, 0, 0.}, 327.676, {2006, 1, 20, 0, 0, 0.}, 326.539, {2006, 1, 20, 3, 0, 0.}, 323.767, {2006, 1, 20, 6, 0, 0.}, 321.039, {2006, 1, 20, 9, 0, 0.}, 318.396, {2006, 1, 20, 12, 0, 0.}, 322.366, {2006, 1, 20, 15, 0, 0.}, 325.274, {2006, 1, 20, 18, 0, 0.}, 325.658, {2006, 1, 20, 21, 0, 0.}, 326.558, {2006, 1, 21, 0, 0, 0.}, 327.196, {2006, 1, 21, 3, 0, 0.}, 323.771, {2006, 1, 21, 6, 0, 0.}, 316.523, {2006, 1, 21, 9, 0, 0.}, 316.252, {2006, 1, 21, 12, 0, 0.}, 321.72, {2006, 1, 21, 15, 0, 0.}, 324.336, {2006, 1, 21, 18, 0, 0.}, 327.127, {2006, 1, 21, 21, 0, 0.}, 328.491, {2006, 1, 22, 0, 0, 0.}, 328.535, {2006, 1, 22, 3, 0, 0.}, 322.131, {2006, 1, 22, 6, 0, 0.}, 318.04, {2006, 1, 22, 9, 0, 0.}, 316.22, {2006, 1, 22, 12, 0, 0.}, 321.768, {2006, 1, 22, 15, 0, 0.}, 322.051, {2006, 1, 22, 18, 0, 0.}, 323.318, {2006, 1, 22, 21, 0, 0.}, 324.169, {2006, 1, 23, 0, 0, 0.}, 324.497, {2006, 1, 23, 3, 0, 0.}, 322.241, {2006, 1, 23, 6, 0, 0.}, 317.922, {2006, 1, 23, 9, 0, 0.}, 317.827, {2006, 1, 23, 12, 0, 0.}, 318.877, {2006, 1, 23, 15, 0, 0.}, 321.213, {2006, 1, 23, 18, 0, 0.}, 322.607, {2006, 1, 23, 21, 0, 0.}, 325.508, {2006, 1, 24, 0, 0, 0.}, 326.516, {2006, 1, 24, 3, 0, 0.}, 325.44, {2006, 1, 24, 6, 0, 0.}, 322.301, {2006, 1, 24, 9, 0, 0.}, 320.571, {2006, 1, 24, 12, 0, 0.}, 323.99, {2006, 1, 24, 15, 0, 0.}, 325.769, {2006, 1, 24, 18, 0, 0.}, 325.893, {2006, 1, 24, 21, 0, 0.}, 323.95, {2006, 1, 25, 0, 0, 0.}, 322.063, {2006, 1, 25, 3, 0, 0.}, 317.175, {2006, 1, 25, 6, 0, 0.}, 311.124, {2006, 1, 25, 9, 0, 0.}, 310.832, {2006, 1, 25, 12, 0, 0.}, 317.104, {2006, 1, 25, 15, 0, 0.}, 319.588, {2006, 1, 25, 18, 0, 0.}, 321.886, {2006, 1, 25, 21, 0, 0.}, 324.605, {2006, 1, 26, 0, 0, 0.}, 325.571, {2006, 1, 26, 3, 0, 0.}, 319.892, {2006, 1, 26, 6, 0, 0.}, 312.419, {2006, 1, 26, 9, 0, 0.}, 311.632, {2006, 1, 26, 12, 0, 0.}, 317.151, {2006, 1, 26, 15, 0, 0.}, 315.756, {2006, 1, 26, 18, 0, 0.}, 309.114, {2006, 1, 26, 21, 0, 0.}, 308.152, {2006, 1, 27, 0, 0, 0.}, 307.869, {2006, 1, 27, 3, 0, 0.}, 306.179, {2006, 1, 27, 6, 0, 0.}, 304.344, {2006, 1, 27, 9, 0, 0.}, 310.731, {2006, 1, 27, 12, 0, 0.}, 312.042, {2006, 1, 27, 15, 0, 0.}, 315.486, {2006, 1, 27, 18, 0, 0.}, 319.399, {2006, 1, 27, 21, 0, 0.}, 326.018, {2006, 1, 28, 0, 0, 0.}, 323.422, {2006, 1, 28, 3, 0, 0.}, 321.549, {2006, 1, 28, 6, 0, 0.}, 315.104, {2006, 1, 28, 9, 0, 0.}, 318.588, {2006, 1, 28, 12, 0, 0.}, 324.495, {2006, 1, 28, 15, 0, 0.}, 329.223, {2006, 1, 28, 18, 0, 0.}, 331.212, {2006, 1, 28, 21, 0, 0.}, 331.474, {2006, 1, 29, 0, 0, 0.}, 333.785, {2006, 1, 29, 3, 0, 0.}, 327.536, {2006, 1, 29, 6, 0, 0.}, 321.733, {2006, 1, 29, 9, 0, 0.}, 318.309, {2006, 1, 29, 12, 0, 0.}, 325.799, {2006, 1, 29, 15, 0, 0.}, 327.442, {2006, 1, 29, 18, 0, 0.}, 327.955, {2006, 1, 29, 21, 0, 0.}, 328.15, {2006, 1, 30, 0, 0, 0.}, 330.915, {2006, 1, 30, 3, 0, 0.}, 326.628, {2006, 1, 30, 6, 0, 0.}, 317.78, {2006, 1, 30, 9, 0, 0.}, 316.483, {2006, 1, 30, 12, 0, 0.}, 322.661, {2006, 1, 30, 15, 0, 0.}, 327.509, {2006, 1, 30, 18, 0, 0.}, 330.479, {2006, 1, 30, 21, 0, 0.}, 333.422, {2006, 1, 31, 0, 0, 0.}, 335.805, {2006, 1, 31, 3, 0, 0.}, 329.932, {2006, 1, 31, 6, 0, 0.}, 322.188, {2006, 1, 31, 9, 0, 0.}, 322.895, {2006, 1, 31, 12, 0, 0.}, 330.111, {2006, 1, 31, 15, 0, 0.}, 333.34, {2006, 1, 31, 18, 0, 0.}, 334.173, {2006, 1, 31, 21, 0, 0.}}

how to find mean of day and month, years value? ... this is only month data.

$\endgroup$
1
  • 2
    $\begingroup$ Dear @BatbuyanMGL, please do not dump big amounts of unformatted data code like this. In any case, your data set looks like it isn't set up properly. $\endgroup$
    – Verbeia
    Commented May 20, 2014 at 5:48

2 Answers 2

6
$\begingroup$

Your data are unbalanced and not arranged appropriately; you need to Partition it into date-value pairs. There is also an errant opening curly bracket at the beginning of your definition of data. I have stripped this out.

You can collect together all the values that occur on the same day using GatherBy, and then apply the Mean or other function you want to apply on each row of data, after stripping out the dates.

Mean /@ (GatherBy[Partition[data, 2], #[[1, 1 ;; 3]] &][[All, All, 2]])

Let's unpack this single-liner. Partition just organises the data into date-value pairs. The GatherBy statement then groups each of these pairs if the first few elements of the date are the same. The specification 1;;3 covers daily data. If you wanted monthly averages, you would use 1;;2 instead. The [[All, All, 2]] bit just ensures that you are only operating on the values, not the dates, and then you can Map (/@) Mean, or whatever other function you desire, to each row of values.

Other questions you might find helpful include this one, this one, and anything else relevant in this search.

Note that version 10 will have some more sophisticated functionality for manipulating time series, including this.

$\endgroup$
1
0
$\begingroup$

Other than what's given in the answer above...

Fastest (both computationally, and logically) way to get Mean and other stats on DateList data (in form {yyyy,mm,dd}) is to convert it to absolute time, then do your operation on integers, then convert the answer(s) back to date(s), which will give you 6 positions, since it'll also return time, which you effectively cut off with Part[;;3]:

dates={{2016,1,1},{2016,6,1},{2017,1,1},{2017,6,1}};
DateList[Mean[AbsoluteTime/@dates]][[;;3]]

returns {2016, 9, 15}

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.