ToExpression[list] will work.
Or you could implement a stricter version:
Replace[
Characters[list] /. Table[ToString[i] -> i, {i, 0, 9}],
{valid : {__Integer} :> FromDigits[valid], _ -> $Failed},
{1}
]
The function you are looking for is called ToExpression. You need to map
it to your list of strings:
amylist={"02", "03", "04", "05", "06", "07", "08", "09"}
Map[ToExpression,amylist]
or abbreviated:
ToExpression /@ amylist
hth,
albert
lstTriple =lstTriple/.{x_,y_,z_}->{x,ToExpression[y],z}
lstTriple;
NumericQ[listTriple[[3,2]]]
True
lstTriple;
NumericQ[listTriple[[3,2]]]
False
After splitting out the column containing numeric string data explicitly to a new single variable list, then running the Map function using ToExpression, and then reassembling the list triple, would Mathematica recognize the numeric and not string format persistently.
Thanks again for the help. - Kurt
----- Original Message ----
From: dh <d...@metrohm.com>
To: Canopus56 <cano...@yahoo.com>
Sent: Mon, January 18, 2010 4:06:33 AM
Subject: Re: Convert string list to number list
Hi,
if you do not want it to convert on input, you may still use e.g. ToExpression:
ToExpression@{"00", "01", "02", "03", "04", "05", "06", "07"}
Daniel
Hi,
if you do not want it to convert on input, you may still use e.g.
ToExpression:
ToExpression@{"00", "01", "02", "03", "04", "05", "06", "07"}
Daniel
>Thanks to all who replied. Even with ToExpression, I was trouble
>getting the string to numeric conversion to persistently take when
>replacing to a list. There was some weird runtime error where you
>could run and get:
>lstTriple =lstTriple/.{x_,y_,z_}->{x,ToExpression[y],z}
>lstTriple;
>NumericQ[listTriple[[3,2]]] True
>lstTriple;
>NumericQ[listTriple[[3,2]]] False
Since there is no object in Mathematica that can be used as an
argument for NumbericQ that will return True and False, you must
have done something you are not showing above that would explain
the result.
>After splitting out the column containing numeric string data
>explicitly to a new single variable list, then running the Map
>function using ToExpression, and then reassembling the list triple,
>would Mathematica recognize the numeric and not string format
>persistently.
After reading this several times, I cannot determine whether you
still have a problem or exactly what you are saying Mathematica
is doing. I will note since
In[6]:= Attributes[ToExpression]
Out[6]= {Listable,Protected}
it is not necessary to use Map in order to covert each string in
a list of strings to a number using ToExpression.
Thanks, Bill. No, I haven't done something else between the first and second NumericQs. I was just illustrating anomalous behavior by the program. The only way to kill the runtime error was to deconstruct the triple into three lists of singles, run "ToExpression" on a one dimensional array {y}, and then reassemble a new triple.
No worries. It is probably something�in the�source data. It's fixed with a brute force, but inelegant solution.
Thanks again, Kurt
----- Original Message ----
From: Bill Rowe <read...@sbcglobal.net>
Sent: Wed, January 20, 2010 4:49:38 AM
Subject: Re: Convert string list to number list