Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2013

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

Search the Archive

Re: Extract columns based on their the title in header

  • To: mathgroup at smc.vnet.net
  • Subject: [mg131696] Re: Extract columns based on their the title in header
  • From: Sseziwa Mukasa <mukasa at gmail.com>
  • Date: Sat, 21 Sep 2013 04:38:50 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-outx@smc.vnet.net
  • Delivered-to: mathgroup-newsendx@smc.vnet.net
  • References: <20130920110717.97AEE6A3D@smc.vnet.net>

I don't know about efficiency, but this expression is clearer to me:

datalist[[All, Flatten[Position[datalist[[1]], "Name" | "Age"]]]]

On Sep 20, 2013, at 7:07 AM, Joug Raw <jougraw at gmail.com> 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?
> 
> 




  • Prev by Date: list mutability (very basic question)
  • Next by Date: Re: Parallel Kernel Status
  • Previous by thread: Re: Extract columns based on their the title in header
  • Next by thread: Re: Extract columns based on their the title in header