This is a follow up question form my last question click here. I have unbalanced panel data such as :
pdata = {{AA, 1, 10}, {AA, 2, 20}, {CC, 3, 30}, {CC, 4, 40}, {CC, 5,
50}, {CC, 6, 60}, {CC, 7, 70}, {DD, 8, 80}, {DD, 9, 90}, {DD, 10,
100}, {EE, 11, 110}, {EE, 12, 120}, {EE, 13, 130}, {HH, 14,
140}, {HH, 15, 150}, {HH, 16, 160}, {HH, 17, 170}, {HH, 18,
180}, {HH, 19, 190}, {HH, 20, 200}};
I want to extract firs and last rows of each group. Thank to both Verbeia and belisarius. With their help I can write:
firstrow = First /@ GatherBy[pdata, First];
lastrow = Last /@ GatherBy[pdata, First];
bothrows = Join @@ Flatten[{firstrow, lastrow}, {{2}, {1}}];
and get my desired result. But my actual data is very big and it takes time if I do this way. I am looking for better and faster way of doing the same. Any help is greatly appreciated.