MathGroup Archive 2002

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

Search the Archive

Re: Data manipulation

  • To: mathgroup at smc.vnet.net
  • Subject: [mg37723] Re: [mg37674] Data manipulation
  • From: Tomas Garza <tgarza01 at prodigy.net.mx>
  • Date: Sat, 9 Nov 2002 00:30:50 -0500 (EST)
  • References: <200211080715.CAA07361@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

This is an elementary problem. You'd do well to get acquainted with the very
basics of Mathematica, which requires little more than a couple of weeks
reading The Book or some textbook on the subject. Anyway, I propose the
first three approaches which come to my mind, to deal with a list of 10,000
pairs.

 In[1]:=
data = Transpose[{Table[Random[Real, {0, 5}], {10000}],
     Range[10000]}];

In[2]:=
Timing[Select[data, 2<= #[[1]]< 4 & ]; ]
Out[2]=
{0.047Second,Null}

In[3]:=
Timing[Cases[data, {x_, y_} /; 2<= x< 4]; ]
Out[3]=
{0.062 Second,Null}

In[4]:=
Timing[data[[Flatten[Position[Transpose[data][[1]],
      x_ /; 2<= x< 4]]]]; ]
Out[4]=
{0.063 Second,Null}

Tomas Garza
Mexico City
----- Original Message -----
From: "Adam Smith" <adam.smith at hillsdale.edu>
To: mathgroup at smc.vnet.net
Subject: [mg37723] [mg37674] Data manipulation


> I know that this has been covered before, but I could not find it.
>
> I have a list of data and I want to select a subset based on a
> condition.
>
> A simple example:
>
> data =
> {{0.39501, 10}, {1.65689, 20}, {2.40239, 30}, {3.27252, 40}, {4.41738,
> 50}}
>
> I want to select only the pairs for which the first element of each
> pair is greater than or equal to 2.0 and less than 4.0  In this case
> the final result would be
>
> {{2.40239, 30}, {3.27252, 40}}
>
> In reality the list is several hundred pairs.
>
> Thanks
>
> Adam
>
>




  • Prev by Date: AW: problem
  • Next by Date: RE: Error Testing a List on input
  • Previous by thread: Data manipulation
  • Next by thread: Re: Data manipulation