From: Ray Koopman on 22 May 2010 23:34 Intersection@@(#[[All,3]]&/@list) will handle a variable number of groups. On May 21, 9:42 pm, Garapata <warsaw95...(a)mypacks.net> wrote: > I have a list with the following dimensionality: > > Dimensions[list] > Dimensions[list[[1]]] > Dimensions[list[[2]]] > Dimensions[list[[3]]] > > {3} > {130, 3} > {126, 3} > {191, 3} > > I think of it as 3 groups, each with a different number of rows, but > each of these rows has 3 columns. Of the 3 columns, the third has > dates in a DateList format. > > So, I can simulate the list with the following: > > a = Table[{RandomInteger[10], RandomInteger[10], DatePlus[{2010, 1, > 1}, RandomInteger[{1, 150}]]}, {1}, {191}]; > list = Join[a[[All, 4 ;; 133, All]], a[[All, 1 ;; 126, All]], a]; > > Ultimately I'd like to find all the rows that intersect on the same > dates and put the whole thing into a 2 dimensional structure that > would have the following columns: > > commonDates, group1Data1, group1Data2, group2Data1, group2Data2, > group3Data1, group3Data2, > > I can use Intersect[] to find the common dates: > > Intersection[list[[1, All,3]], list[[2, All, 3]], list[[3, All, > 3]]]; > > but this seems a bit cumbersome given I may have a greater or lesser > number of groups. Seems like I need to start this in a better way, > but since Intersection[] doesn't take a list of lists I don't know > where to take this. > > Probably easier if I had a more regular structure but I don't. > > Any help in pointing me in the right direction much appreciated. > > Thx to all.
From: Garapata on 23 May 2010 03:17 A friend working serendipitously on a very similar problem got a step of the solution from Wolfram Support (credit where credit's due, they seem to have made some real improvements over there). Anyway, since I have unique dates within each of the groups described in my original post I can use Part to pull out all of the dates, something like this: groupDates = list[[All,All, 3]] Then I can use this elegant solution via Wolfram support: datesIntersection = Apply[Intersection, groupDates] Doesn't get me all the way to what I need, but looks like a good start. Remember I still need to get to this (from my original post): .... I'd like to find all the rows that intersect on the same dates and put the whole thing into a 2 dimensional structure that would have the following columns: commonDates, group1Data1, group1Data2, group2Data1, group2Data2, group3Data1, group3Data2 .... So any help still very much appreciated. Thx
From: Ray Koopman on 23 May 2010 03:17 Further to my earlier post, the whole thing would then be Function[i,Flatten@{i,Cases[#,{x_,y_,i}:>{x,y},{1},1]&/@list}] /@ Intersection@@(#[[All,3]]&/@list) On May 21, 9:42 pm, Garapata <warsaw95...(a)mypacks.net> wrote: > I have a list with the following dimensionality: > > Dimensions[list] > Dimensions[list[[1]]] > Dimensions[list[[2]]] > Dimensions[list[[3]]] > > {3} > {130, 3} > {126, 3} > {191, 3} > > I think of it as 3 groups, each with a different number of rows, but > each of these rows has 3 columns. Of the 3 columns, the third has > dates in a DateList format. > > So, I can simulate the list with the following: > > a = Table[{RandomInteger[10], RandomInteger[10], DatePlus[{2010, 1, > 1}, RandomInteger[{1, 150}]]}, {1}, {191}]; > list = Join[a[[All, 4 ;; 133, All]], a[[All, 1 ;; 126, All]], a]; > > Ultimately I'd like to find all the rows that intersect on the same > dates and put the whole thing into a 2 dimensional structure that > would have the following columns: > > commonDates, group1Data1, group1Data2, group2Data1, group2Data2, > group3Data1, group3Data2, > > I can use Intersect[] to find the common dates: > > Intersection[list[[1, All,3]], list[[2, All, 3]], list[[3, All, > 3]]]; > > but this seems a bit cumbersome given I may have a greater or lesser > number of groups. Seems like I need to start this in a better way, > but since Intersection[] doesn't take a list of lists I don't know > where to take this. > > Probably easier if I had a more regular structure but I don't. > > Any help in pointing me in the right direction much appreciated. > > Thx to all.
|
Pages: 1 Prev: Usage Messages; % evaluates to Null. Why? Next: Just some thousands of combinations... |