Skip to main content
deleted 2 characters in body
Source Link
andre314
  • 19k
  • 1
  • 37
  • 73

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

enter image description here

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.

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

enter image description here

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 if votes is a ragged array.

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

enter image description here

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.

I have followed your inital idea to use ReplacePart, but ReplacePart may not be the best approach.

added 362 characters in body
Source Link
andre314
  • 19k
  • 1
  • 37
  • 73

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[
   tabReplacePart[tab,
   {i_, j_} :> (If[# =!= {}, #[[1, 1]], "-"]tab[[i, j]] ] & @ 
           Position[votes[[i, All]], tab[[i, j]]])];

res // Grid

enter image description hereenter image description here

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 if votes is a ragged array.

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]], "-"] & @ 
           Position[votes[[i, All]], tab[[i, j]]])];

res // Grid

enter image description here

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 if votes is a ragged array.

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

enter image description here

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 if votes is a ragged array.

added 362 characters in body
Source Link
andre314
  • 19k
  • 1
  • 37
  • 73

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]], "-"] & @ 
           Position[votes[[i, All]], tab[[i, j]]])];

res // Grid

enter image description here

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 if votes is a ragged array.

ReplacePart works with named pattern :

ReplacePart[tab, {i_, 2} :> Position[votes[[i, All]], ff][[1, 1]]]

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.

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]], "-"] & @ 
           Position[votes[[i, All]], tab[[i, j]]])];

res // Grid

enter image description here

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 if votes is a ragged array.

Source Link
andre314
  • 19k
  • 1
  • 37
  • 73
Loading