On importing a space delimited text file, I have an extracted list of zero-padded two-digit integers in the form: Amylist{"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"} How do I convert these to real numbers or integers? Thanks - Kurt I have reviewed the Mathematica documentation and a few books looking for the equivalent of a simple string-to-number function like vba's "Value". Could not find an answer. Thanks.
|
|
0
|
|
|
|
Reply
|
Canopus56
|
1/18/2010 7:34:37 AM |
|
On Jan 17, 11:34 pm, Canopus56 <canopu...@yahoo.com> wrote:
> On importing a space delimited text file, I have an extracted list of
zero-padded two-digit integers in the form: Amylist{"00", "01", "02", "03",
"04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"} How do I convert these to
real numbers or integers? Thanks - Kurt I have reviewed the Mathematica
documentation and a few books looking for the equivalent of a simple string-to-number function like vba's "Value". Could not find an answer. Thanks .
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}
]
|
|
0
|
|
|
|
Reply
|
Raffy
|
1/18/2010 10:41:18 AM
|
|
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
Canopus56 wrote:
> On importing a space delimited text file, I have an extracted list of zero-padded two-digit integers in the form: Amylist{"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"} How do I convert these to real numbers or integers? Thanks - Kurt I have reviewed the Mathematica documentation and a few books looking for the equivalent of a simple string-to-number function like vba's "Value". Could not find an answer. Thanks.
>
|
|
0
|
|
|
|
Reply
|
dh
|
1/19/2010 10:13:52 AM
|
|
Am 18.01.2010 08:34, schrieb Canopus56:
> On importing a space delimited text file, I have an extracted list
> of zero-padded two-digit integers in the form: Amylist{"00", "01",
> "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12",
> "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"}
> How do I convert these to real numbers or integers? Thanks - Kurt I
> have reviewed the Mathematica documentation and a few books looking
> for the equivalent of a simple string-to-number function like vba's
> "Value". Could not find an answer. Thanks.
>
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
|
|
0
|
|
|
|
Reply
|
Albert
|
1/19/2010 10:14:25 AM
|
|
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
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 <dh@metrohm.com>
To: Canopus56 <canopus56@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
Canopus56 wrote:
> On importing a space delimited text file, I have an extracted list of zero-padded two-digit integers in the form: Amylist{"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"} How do I convert these to real numbers or integers? Thanks - Kurt I have reviewed the Mathematica documentation and a few books looking for the equivalent of a simple string-to-number function like vba's "Value". Could not find an answer. Thanks.
|
|
0
|
|
|
|
Reply
|
Canopus56
|
1/19/2010 10:14:47 AM
|
|
|
4 Replies
628 Views
(page loaded in 0.073 seconds)
Similiar Articles: Convert string list to number list - comp.soft-sys.math ...On Jan 17, 11:34 pm, Canopus56 <canopu...@yahoo.com> wrote: > On importing a space delimited text file, I have an extracted list of zero-padded two-digit integers in ... [tempo] Convert variable from string to number - comp.emacs ...I'd like to convert (the value of) a variable inside a tempo template from a string to a number. This doesn't work: (tempo-define-template "whatsis" ... String to number conversion - comp.soft-sys.matlabConvert string list to number list - comp.soft-sys.math ..... and a few books looking > for the equivalent of a simple string-to-number ... String to integer conversion ... convert integer to string - comp.lang.perl.miscConvert string list to number list - comp.soft-sys.math ... On Jan 17, 11:34 pm, Canopus56 <canopu...@yahoo.com> wrote: > On importing a space delimited text file, I have ... Convert month name to month number faster - comp.lang.python ...Convert string list to number list - comp.soft-sys.math ... convert integer to string - comp.lang.perl.misc Convert string list to number list - comp.soft-sys.math ... How to convert characters to number - comp.lang.fortranConvert string list to number list - comp.soft-sys.math ... converting a character string into a variable name - comp.lang ... Convert string list to number list - comp ... How to convert bytearray into integer? - comp.lang.python ...How to convert bytearray into integer? - comp.lang.python ... Convert string list to number list - comp.soft-sys.math ... On importing a space delimited text file, I have ... convert string to ascii - comp.soft-sys.matlabConvert string list to number list - comp.soft-sys.math ... convert string to ascii - comp.soft-sys.matlab Convert string list to number list - comp.soft-sys.math ... Convert comma separated string to cellarray - comp.soft-sys.matlab ...Convert string list to number list - comp.soft-sys.math ... Convert string list to number list - comp.soft-sys.math ... Convert month name to month number faster - comp ... Converting number to std::string ("itoa()" ) - comp.lang.c++ ...Hello, What would you recommend is the best way to construct a std::string from a numerical variable (eg an int). Ive found _itoa() function... Convert List of Numbers to a range stringHi Am using an A2k app in which I want to convert a list of numbers (1,2,3,4,5,8,9,10,12) into something that looks like (1-5, 8-9, 12). Is there any ... Convert string list to number list"04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"} How do I convert these to 7/19/2012 9:00:35 PM
|