Re: How to extract numbers from list elements with text?
- To: mathgroup at smc.vnet.net
- Subject: [mg70371] Re: How to extract numbers from list elements with text?
- From: Bill Rowe <readnewsciv at sbcglobal.net>
- Date: Sat, 14 Oct 2006 03:07:55 -0400 (EDT)
On 10/13/06 at 1:30 AM, henning.heibergandersen at gmail.com (Henning
Heiberg-Andersen) wrote:
>I have a list looking like this:
>{ 1 Intensity 0.23523, 2 Intensity 0.00005, 3 Intensity 0.00004,
>..}
>Is there a command which allows extraction of only the last number
>appearing in each element of the list?. If not, how can I modify the
>list elements?
Mathematica would interpret 1 Intensity 0.23523 as the product
of the integer 1, symbol Intensity and machine precision number
0.23523, returning
In[1]:=
1 Intensity 0.23523
Out[1]=
0.23523 Intensity
So, I assume your list is really
{ "1 Intensity 0.23523", "2 Intensity 0.00005", "3 Intensity
0.00004", ..}
and I will further assume you want the last portion of the
string returned as a numeric quantity in Mathematica.
If I have what you want correct, then you can achieve what you
want as follows:
In[2]:=
list={"1 Intensity 0.23523","2 Intensity 0.00005","3 Intensity 0.00004"};
In[3]:=
ToExpression[Last@StringSplit@#]&/@list
Out[3]=
{0.23523,0.00005,0.00004}
checking
In[4]:=
NumericQ/@%
Out[4]=
{True,True,True}
--
To reply via email subtract one hundred and four