Group Abstract Group Abstract

Message Boards Message Boards

0
|
6K Views
|
5 Replies
|
3 Total Likes
View groups...
Share
Share this post:

[?] Select specific data from a list?

Posted 8 years ago
POSTED BY: Joana Schenk
5 Replies
Posted 8 years ago

Thanks for your help! After trying around and asking for help I was able to figure it out. Thank you!

POSTED BY: Joana Schenk
Posted 8 years ago

This is starting to smell like school homework! I might be wrong. Could you show what you have done this far?

Anyway, it seems that you are looking to extract the 2nd column from a n by 2 matrix.

The function Part will fix it. Check out the documentation: Getting and Setting Pieces of Matrices

POSTED BY: Hans Milton
Posted 8 years ago

Thank you Hans and Marco for your help!

I was able to select the data so that just the data shows up for each fuel type. How would I be able to just select the kilometers driven (i.e. the integer values) which are linked to the fuel types?

I'm asking because I would like to have a list of just the kilometers driven for each fuel type and from there calculate the mean driven for each fuel type.

POSTED BY: Joana Schenk
Posted 8 years ago

This is what Cases is made for.

In[11]:= data = Table[{RandomChoice@{"E", "D", "P"}, RandomInteger@100}, 20]

Out[11]= {{"D", 25}, {"D", 4}, {"D", 55}, {"E", 29}, {"E", 8}, {"D", 
  19}, {"P", 17}, {"P", 42}, {"D", 65}, {"D", 13}, {"E", 53}, {"D", 
  30}, {"D", 98}, {"E", 83}, {"E", 28}, {"D", 7}, {"E", 11}, {"E", 
  86}, {"P", 11}, {"E", 82}}

In[12]:= Cases[data, {"E", _}]

Out[12]= {{"E", 29}, {"E", 8}, {"E", 53}, {"E", 83}, {"E", 28}, {"E", 
  11}, {"E", 86}, {"E", 82}}
POSTED BY: Hans Milton

What about this?

fueltype = {"Super (E10)", "Diesel", "Electricity", "Petrol", "Plug In"};
data = Transpose[{RandomChoice[fueltype, 20], RandomInteger[80, 20]}];

This gives something like:

enter image description here

Now,

Select[data, #[[1]] == "Diesel" &]

should help.

Cheers,

Marco

POSTED BY: Marco Thiel
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard