I have a long list of triples, each looking something like {AGO, 1988, 2345.23}
. Some of these, however, have an integer in the third spot, like this: {IND, 1993, 4345}
because of the nature of the original data. I do not want integers, because I have to Log this data eventually.
So I thought I would map the following function through my list:
fn[s_List] := s //. {a_, b_, c_} /; IntegerQ[c] -> {a, b, N[c]}
It does not work. I want it to put "4345." in place of "4345".
However, I can use the following to get a very good approximation:
fnn[s_List] := s //. {a_, b_, c_} /; IntegerQ[c] -> {a, b, c-.00001}
But, even though the loss of precision is not important for this project, I'd like to know why my first function does not work.
I have been working with these kinds of replacement rules a lot recently, and this one seems pretty simple.
Any help is very much appreciated.
fn[s_List] := s //. {a_, b_, c_} /; IntegerQ[c] :> {a, b, 1. c}
$\endgroup$ – Dr. belisarius Dec 14 '13 at 4:03ReplaceRepeated
(//.
) should be unnecessary. TryReplaceAll
(/.
). $\endgroup$ – Michael E2 Dec 14 '13 at 4:06fn[s_List] := s /. {a_, b_, c_Integer} :> {a, b, N@c}
$\endgroup$ – RunnyKine Dec 14 '13 at 4:09N@list
orMapAt[N, list, {All, 3}]
also works. $\endgroup$ – István Zachar Dec 14 '13 at 12:46