The Math Forum

Search All of the Math Forum:

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

Math Forum » Discussions » Inactive » comp.soft-sys.math.mathematica

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

Advanced Search

Back to Topic List Back to Topic List  

Posts: 22
Registered: 5/30/12
Extract columns based on their the title in header
Posted: Sep 20, 2013 7:03 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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?

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.