| Author |
Comment/Response |
Bill Simpson
|
02/26/13 00:26am
In[1]:= a={{1,1,1,2,2,2},{2,4,3,4,5,3}};
at=Transpose[a];
ad=DeleteDuplicates[First[a]];
al=Map[Cases[at,{#,v_}->v]&,ad];
Map[Mean,al]
Out[5]= {3,4}
That should work fine, but if your input might ever be something like
a={{1,1,2,2,1,1},{2,4,3,4,5,3}}
and you expect the output to be
{3,7/2,4}
then DeleteDuplicates may not be the function to use. If that could ever happen then this might work.
In[7]:= a={{1,1,2,2,1,1},{2,4,3,4,5,3}};
at=Transpose[a];
as=Split[at,First[#1]==First[#2]&];
Map[Last,Map[Mean,as]]
Out[10]= {3, 7/2, 4}
URL: , |
|