Re: Replace non-numeric values in a list
- To: mathgroup at smc.vnet.net
- Subject: [mg88787] Re: [mg88745] Replace non-numeric values in a list
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Fri, 16 May 2008 05:34:35 -0400 (EDT)
- Reply-to: hanlonr at cox.net
list = {a, 1, 2, b, 3};
If[NumericQ[#], #, 0] & /@ list
{0,1,2,0,3}
list (Boole[NumericQ[#]] & /@ list)
{0,1,2,0,3}
Replace[list, _?(Not[NumericQ[#]] &) -> 0, 1]
{0,1,2,0,3}
Bob Hanlon
---- Adel Elsabbagh <aelsabbagh at gmail.com> 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
>
>