I have a fairly complicated expression with nested lists and I want to substitute a given string for each integer. Here's a simple example where ind is my integer-valued data structure and names is the list of strings.
ind = RandomInteger[{1, 5}, {3, 4, 5}];
names = {"one", "two", "three", "four", "five"};
ind /. {n_Integer -> names[[n]]}
This returns two things: first, a list with the integers substituted by their string names (that's good) and an error (that's bad). The error is:
Part: The expression n cannot be used as a part specification.
though of course it has been used correctly as a part spec. The question: is it really incorrect to be using a list (and an index to the list) in the replacement rule? Is there a better way of doing this?
:>
, right? $\endgroup$ – Kuba♦ Mar 19 at 17:15IntegerName /@ ind
. $\endgroup$ – High Performance Mark Mar 19 at 17:25