Re: Construcing correlation matrix from time-ordered list
- To: mathgroup at smc.vnet.net
- Subject: [mg54749] Re: [mg54707] Construcing correlation matrix from time-ordered list
- From: DrBob <drbob at bigfoot.com>
- Date: Mon, 28 Feb 2005 03:28:44 -0500 (EST)
- References: <200502270629.BAA25482@smc.vnet.net>
- Reply-to: drbob at bigfoot.com
- Sender: owner-wri-mathgroup at wolfram.com
{{1897, 1, 4}, 40.37`} clearly isn't just "the year, then the value", so I'm assuming each entry is actually {{year, month, day}, value}. The table you seem to want can't be filled if there's not an equal number of data points for each year, and it's not clear how you're defining rows - based on month and day, maybe? Even this much may be useful to you: data={{{1897,1,4},40.37`},{{1897,1,5},40.87`},{{1897,1,6},40.95`},{{1897,1, 7},40.87`},{{1897,1,8},40.97`},{{1897,1, 11},40.75`},{{1897,1,12},41.4`},{{1897,1, 13},41.45`},{{1897,1,14},41.79`},{{1897,1,15},42.27`},{{ 1897,1,18},42.76`},{{1897,1,19},43.25`},{{ 1897,1,20},42.78`},{{1897,1,21},42.52`},{{1897,1,22},42.42`}}; Transpose@{data[[All,1,1]],data[[All,2]]} {{1897,40.37},{1897,40.87},{1897,40.95},{1897,40.87},{ 1897,40.97},{1897,40.75},{ 1897,41.4},{1897,41.45},{1897,41.79},{1897,42.27},{1897,42.76},{ 1897,43.25},{1897,42.78},{1897,42.52},{1897,42.42}} Beyond that, here's an approach that counts entries in each year and defines rows from one to the maximum count. (inputs:) Clear[f, count] count[_] = 0; Scan[(f[#[[1, 1]], count[#[[1, 1]]]++] = #[[2]]) &, data] {maxYear, minYear} = Through[{Max, Min}@data[[All, 1, 1]]] maxRows = Max[count /@ Range[minYear, maxYear]] TableForm[Table[f[year, row], {row, 0, maxRows - 1}, {year, minYear, maxYear}], TableHeadings -> {None, Range[minYear, maxYear]}] (outputs:) {1897,1897} 15 TableForm[{{1897}, {40.37}, {40.87}, {40.95}, {40.87}, {40.97}, {40.75}, {41.4}, {41.45}, {41.79}, {42.27}, {42.76}, {43.25}, {42.78}, {42.52}, {42.42}}, TableHeadings -> {None, {1897}}] Bobby On Sun, 27 Feb 2005 01:29:57 -0500 (EST), Adam Getchell <agetchell at physics.ucdavis.edu> wrote: > Hello all, > > I have time series data (a lot of it) in a format like: > > {{{1897,1,4},40.37`},{{1897,1,5},40.87`},{{1897,1,6},40.95`},{{1897,1,7}, > 40.87`},{{1897,1,8},40.97`},{{1897,1,11},40.75`},{{1897,1,12}, > 41.4`},{{1897,1,13},41.45`},{{1897,1,14},41.79`},{{1897,1,15}, > 42.27`},{{1897,1,18},42.76`},{{1897,1,19},43.25`},{{1897,1,20}, > 42.78`},{{1897,1,21},42.52`},{{1897,1,22},42.42`}} > > ie the year, then the value, for 100+ years. > > I'd like to construct a correlation matrix so that year values become > columns, e.g. > > 1897 1898 > ========== > Value1 Value 1 > Value 2 Value 2 > ... > > From my long list of {{{date1},value1},{{date2},value2}} > > But I'm not yet sure how to proceed. I'm looking at Cases or Select to > apply a function for each year range that will pick out that column. > > Any pointers appreciated. > > --Adam Getchell > > > > > -- DrBob at bigfoot.com www.eclecticdreams.net
- References:
- Construcing correlation matrix from time-ordered list
- From: Adam Getchell <agetchell@physics.ucdavis.edu>
- Construcing correlation matrix from time-ordered list