ReplacePart
works with named pattern, for example you can do :
ReplacePart[tab, {i_, 2} :> Position[votes[[i, All]], ff][[1, 1]]]
So, once you will have corrected the question, the definitve answer is :
res = ReplacePart[tab,
{i_, j_} :> (If[# =!= {}, #[[1, 1]], tab[[i, j]] ] & @
Position[votes[[i, All]], tab[[i, j]]])];
res // Grid
Do not forget to use a delayed rule (:>
instead of ->
)
ReplacePart
is not memory/speed optimal. It may be slow and memory consuming with large data sets.
This code is only interesting ifI have followed your inital idea to use votesReplacePart
is a ragged array, but ReplacePart
may not be the best approach.