# [✓] Select specific data from a list?

Posted 10 months ago
820 Views
|
5 Replies
|
3 Total Likes
|
 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!
5 Replies
Sort By:
Posted 10 months ago
 What about this? fueltype = {"Super (E10)", "Diesel", "Electricity", "Petrol", "Plug In"}; data = Transpose[{RandomChoice[fueltype, 20], RandomInteger[80, 20]}]; This gives something like:Now, Select[data, #[[1]] == "Diesel" &] should help.Cheers,Marco
Posted 10 months 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 10 months 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.