MathGroup Archive 2012

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

Search the Archive

Re: How to remove the Null character in a Table?


Sounds a little farfetched, but this is a nice example to introduce the use of Sow and Reap:
In[1]:= Reap[Sow[#, # < 3] & /@ Table[i, {i, 5}], True][[2, 1]]
Out[1]= {1, 2}
Something simpler might be
In[3]:= Cases[Table[If[i < 3, i,], {i, 5}], _?NumberQ]
Out[3]= {1, 2}
or even simpler
In[7]:= Select[Table[If[i < 3, i,], {i, 5}], NumberQ[#] &]
Out[7]= {1, 2}
-Tomas



> Date: Mon, 16 Jan 2012 17:11:34 -0500
> From: aoirex at gmail.com
> Subject: How to remove the Null character in a Table?
> To: mathgroup at smc.vnet.net
>
> For example,
>
> Table[If[i < 3, i,], {i, 5}]
> will give
> {1, 2, Null, Null, Null}
>
> But I want the result to be {1,2}.
>
> Any trick for this?
>


  • Prev by Date: Re: Extract a part of expression
  • Next by Date: Re: How to simplify this code with variable number of nesting loops?
  • Previous by thread: Re: How to remove the Null character in a Table?
  • Next by thread: Re: How to remove the Null character in a Table?