Message Boards Message Boards

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

[?] Select specific data from a list?

Posted 6 years ago

Hello Wolfram community,

I'm currently trying to analyze the relationship between the fuel type of a car and the distance that was driven with it. To do so, I have transposed two columns from a data set. My next step is to visualize this in some form by separating it by fuel type and showing the mean distance traveled with that type of car.

To do so however, I need to select specific data from the transposed data set. I started making a Select Function, but kept receiving error message. My list of data looks as follows:

{{"Electricity", 34} , {"Diesel",10} , {"Plug In",49} , {......}}

If I wanted to select only the combinations with "Electricity," how would I go about this?

Any help is greatly appreciated! Cheers!

POSTED BY: Joana Schenk
5 Replies
Posted 6 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 6 years ago
POSTED BY: Hans Milton
Posted 6 years ago
POSTED BY: Joana Schenk
Posted 6 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
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

Group Abstract Group Abstract