# Nest Replace Function with different rules

I have a table of data that I want to filter.

Any value of zero in the table means that value was not calculated, so it should get populated with the tag "NC". Next the table is filtered for all those values that line within 0.25 of -1.51. Finally the table is cleaned up and "1.51 + NC" gets removed.

The series of replacements works just fine, but it is extremely messy and unclear. Can any one propose a more readable/easier to understand version? In the real version test is a 27 X 27 table.

test = {{0, -1, -1.5, -1.45}}
targets = {ORR -> -1.51, CORedCO -> -1.2, ORedCO -> -1.25, HER -> -0.24}

Replace[Replace[
Replace[test , a_ /; a == 0 -> "NC", {2}] - ORR /.
targets, a_ /; Abs[a] >= 0.25 -> 0, {2}],
a_ /; a == (-ORR /. targets) + "NC" -> "NC", {2}]


the correct output is:

{"NC", 0, 0.01, 0.06}}

• Perhaps I'm missing the point, but why go through these machinations: If the end result is driven by the rules described, test /. {0 -> "NC", x_ /; Abs[-1.51 - x] >= .25 -> 0, x_ /; x != 0 :> x + 1.51} suffices. One-shot, done...
– ciao
Commented Jun 16, 2014 at 19:57
• @rasher The only reason for me to go through these series of replace was simply my own nieve solution. I had tried to make an elegant one like yourself but I failed. Commented Jun 17, 2014 at 3:00

test = {{0, -1, -1.5, -1.45}};