Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

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 onethis one, this onethis one, and anything else relevant in this searchthis search.

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

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.

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.

Source Link
Verbeia
  • 34.5k
  • 10
  • 110
  • 225

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.