Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Extract columns based on their the title in header
Replies: 6   Last Post: Oct 20, 2013 11:01 PM

 Messages: [ Previous | Next ]
 Dr.J Posts: 22 Registered: 5/30/12
Re: Extract columns based on their the title in header
Posted: Sep 21, 2013 4:35 AM

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

>>--
>>Itai Seggev
>>Mathematica Algorithms R&D

What I want is not to use the number, but the string of the column name.
Because, in reality my table would be super long with thousands of columns.
It is hard for me to know which information stored in which columns, but
the names of the columns have kind of order that allows me to guess. That
is why I need to start from the name string.

On Fri, Sep 20, 2013 at 5:26 PM, Itai Seggev <itais@wolfram.com> wrote:

> 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
>

Date Subject Author
9/21/13 Dr.J
9/21/13 Sseziwa Mukasa
9/21/13 Itai Seggev
9/21/13 Bob Hanlon
9/21/13 Dr.J
10/20/13 Trichy V. Krishnan