MathGroup Archive 2005

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

Search the Archive

Re: Re: enumerating list items

  • To: mathgroup at smc.vnet.net
  • Subject: [mg56058] Re: [mg55986] Re: [mg55976] enumerating list items
  • From: Chris Chiasson <chris.chiasson at gmail.com>
  • Date: Thu, 14 Apr 2005 08:55:41 -0400 (EDT)
  • References: <4FDA877403669E48A2CB7F1122A7948045C6BA@dassne02.da.gei> <200504130510.BAA09473@smc.vnet.net>
  • Reply-to: Chris Chiasson <chris.chiasson at gmail.com>
  • Sender: owner-wri-mathgroup at wolfram.com

Soren,
try this instead:
1. store the database information as an array
2. set the column names (in symbol form using toexpression) equal to
the number of their corresponding columns
3. access the data using the following part expression: dataarray[[columnname]]

You will probably have an easy time of this if you already know how to
import from a database using Mathematica...

On 4/13/05, Søren Merser <merser at image.dk> wrote:
> thanks for your reply
> what i really want is:
> i'm getting data from a database link, including column headers
> assigning  1 : ncols to these names  should enable call column[data,
> colum-index-by-name]
> (or better: assign each data column to it's header name)
> regards søren
> 
> ----- Original Message -----
> From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
To: mathgroup at smc.vnet.net
> Subject: [mg56058] [mg55986] Re: [mg55976] enumerating list items
> 
> >-----Original Message-----
> >From: Søren Merser [mailto:merser at image.dk]
To: mathgroup at smc.vnet.net
> >Sent: Tuesday, April 12, 2005 11:27 AM
> >Subject: [mg56058] [mg55986] [mg55976] enumerating list items
> >
> >hi
> >
> >is there a way to make each item in the list 'assignable',
> >i.e. i want to
> >enumerate the items like id=1, gender=2 etc.
> >
> >a={"id", "gender", "status", "odag"}
> >
> >b=Range@Length@a
> >
> >a=b
> >
> >regards soren
> >
> >
> >
> 
> You have to convert the strings to symbols, before you can assign to them.
> This works, provided the symbols already don't exist with values:
> 
> In[1]:= a={"id","gender","status","odag"};
> 
> In[2]:= MapIndexed[(Evaluate[Symbol[#1]]=First[#2])&,a];
> 
> In[3]:= ?status
>         Global`status
>         status = 3
> 
> Or
> 
> In[4]:= Clear/@ a;    (* to repeat that, we first have to clear the symbols
> *)
> 
> In[5]:= MapThread[Set,{Symbol/@a , Range[Length[a]]}];
> 
> In[6]:= ?odag
>         Global`odag
>         odag = 4
> 
> The question as how to proceed when you want to change values, and you only
> have the names at hand, is not trivial but a FAQ, see the archive, if you
> are interested.
> 
> Good advice to you depends on what you really want to do. If you just want
> to associate your "names" with values you might better proceed differently
> (assoc here is the name of your association):
> 
> In[7]:= Thread[Evaluate[assoc /@ a] = Range[Length[a]]]
> Out[7]= {1, 2, 3, 4}
> 
> This retrieves a "value":
> 
> In[8]:= assoc["gender"]
> Out[8]= 2
> 
> This re-assigns a "value":
> 
> In[9]:= assoc["gender"] = 999
> Out[9]= 999
> 
> --
> Hartmut Wolf
> 
> 


-- 
Chris Chiasson
Kettering University
Mechanical Engineering
Graduate Student
1 810 265 3161


  • Prev by Date: Re: Infinite sum of gaussians
  • Next by Date: Re: Infinite sum of gaussians
  • Previous by thread: Re: enumerating list items
  • Next by thread: Re: enumerating list items