MathGroup Archive 2013

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

Search the Archive

Re: Extract columns based on their the title in header


On Fri, Sep 20, 2013 at 07:07:17AM -0400, Joug Raw wrote:
> 
> I import a CSV file like this:
> 
> Name, Sex, Age, ... , ...
> Tom,     M,  12, ... ,...
> Bob,      M,  13,
> Lily,       F,   11,
> Jack,      M,  14,
> Micheal, M,   10,
> ..
> 
> It become a list and I call it datalist. Then I want only extract the Name
> and Age for each child in the list. I did some thing like:
> 
>  ColumPos =
>  Map[#[[2]] &,
>   Map[Position[datalist, #] &, {"Name",
>     "Age"}], {2}]
> Map[Extract[#, ColumPos] &, datalist]
> 
> Yes, it works. But the code are bit complicated. Any one has any idea to
> get it done in a more efficient way?


datalist[[All,{1,3}]]

--
Itai Seggev
Mathematica Algorithms R&D
217-398-0700 



  • Prev by Date: Re: apply rule to Partition
  • Next by Date: Re: plotting integrals
  • Previous by thread: Re: Extract columns based on their the title in header
  • Next by thread: plotting integrals