MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Replace non-numeric values in a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg88790] Re: [mg88745] Replace non-numeric values in a list
  • From: Syd Geraghty <sydgeraghty at mac.com>
  • Date: Fri, 16 May 2008 05:35:10 -0400 (EDT)
  • References: <200805151150.HAA23460@smc.vnet.net>

Hi Adel,

a really straightforward method would be (assuming your list  
explicitly contains letters and numbers only as in your example)

In[1]= list = {a, 1, 2, b, 3};

In[2]= isletter[a_] := If[LetterQ[ToString[a]], True, False]

In[3]= newlist = Table[If[isletter[list[[i]]], 0, list[[i]]], {i,  
Length[list]}]

Out[4]= {0, 1, 2, 0, 3}

HTH,

Syd Geraghty B.Sc, M.Sc.

sydgeraghty at mac.com

My System

Mathematica 6.0.2.1 for Mac OS X x86 (64 - bit) (March 13, 2008)
MacOS X V 10.5.2
MacBook Pro 2.33 Ghz Intel Core 2 Duo  2GB RAM






On May 15, 2008, at 4:50 AM, Adel Elsabbagh wrote:

> Dear all,
>
> I have a list that contains numeric and non-numeric values
> list = { a, 1, 2, b, 3};
> How can I replace non-numeric values with zeros?
> Thanks!
>
> -- 
> Adel Elsabbagh
> http://www.svlab-asu.com/aelsabbagh.html
>
>



  • Prev by Date: Re: Multiple clipboards
  • Next by Date: Re: Replace non-numeric values in a list
  • Previous by thread: Replace non-numeric values in a list
  • Next by thread: Re: Replace non-numeric values in a list