I am 'Map'ping over a list. I would like to do the computation in one single iteration. Is it possible? Can 'Apply' be used here? In what way is it different from 'Map' especially in this case?
eventnindicators= {{10,0,1},{11,1,1},{15,0,1},{100,1,2},{9,0,2},{10,1,2},{105,0,2}};
censorIndicators= {0,1,0,1,0,1,0};
expectedcnt1 = Function[{c},
Length@Pick[censorIndicators, Sort[eventnindicators], _?(First[#] >= First[c] &)]
] /@ Union[eventnindicators];
Is that too much of code? If yes, please let me know the lines to remove. I am looking for a very general idea to make this faster.
The gist is that I try to do a number of 'Picks' and 'Counts' using #, where I iterate over each of the elements INSIDE the 'Map' function, which actually iterates over a list itself. Is there anyway to cutdown these iterative processes? Is it possible to 'Pick' or 'Count' without the # s? Also, is it possible to not use 'Map' at all here?
Thanks.
N[#,5]? In the given example it does not matter, and, if possible, it'd be nice to remove excess clutter. Also, why are you usingReturnat all? – VF1 Nov 24 '12 at 3:33Reverse@Accumulate@Flatten[# UnitVector[#, 1] & /@ Reverse@Tally[Sort[eventnindicators[[All, 1]]]][[All, 2]]]... is that really the kind of thing that you wanted? – Oleksandr R. Nov 24 '12 at 3:45