Message Boards Message Boards

0
|
3269 Views
|
4 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Filtering based on Category

Posted 9 years ago

I've got a list of categories that I'm trying to sort a list of with one of those industries and gps data. So basically I want to subdivide a list by the first String variable then Graph each category.

My list looks like

  {Industry,{Xcoord, Ycoord}} 

So this is what I've come up with so far, but it's not even close to working,

Aerospace = dataset[[;;,{1,2}]] /. {Industry_,Coords_}:>{Cases[StringMatchQ[Industry,"Aerospace"]],Coords}
POSTED BY: Buck Huffman
4 Replies
Posted 9 years ago

byIndustry = GroupBy[coords, First, Point[Map[GeoPosition, #[[All, 2]]]] &];

I can now break each industry down like this and map it: Graphics[{Gray,State,Red,byIndustry[[1]]}] Graphics[{Gray,State,Red,byIndustry[[2]]}]

So now I need to put each byIndustry into its own tab in Tabview.

POSTED BY: Buck Huffman

The worst case senerio is that you use Keys and Values for the Association and code it out in a for loop. But here's how I would do it. Here's some randomly generated data that looks like what you described:

randomExampleData = Table[{RandomChoice[{"IndustryA", "IndustryB"}], RandomReal[1, 2]}, {100}]

Group them by their first argument and then reduce the sets by selecting the 2nd part of them:

byIndustry = GroupBy[randomExampleData, First, #[[All, 2]] &]

We can map ListPlot onto the results and wrap it in a TabView:

TabView[Map[ListPlot, byIndustry]]
POSTED BY: Sean Clarke
Posted 9 years ago

That's exactly what I was trying to do. Now I want to put each industry in its own TabView. I can break out each Industry like this:

Industry1Points=Point[Map[GeoPosition,Industry1[[All,2]]]]; Industry2Points=Point[Map[GeoPosition,Industry2[[All,2]]]];

TabView[{ Industry1->Graphics[{Gray,State,Red,Industry1Points}], Industry2->Graphics[{Gray,State,Red,Industry2Points}], }]

Is there a way to do this without breaking out each industry?

POSTED BY: Buck Huffman

The first thing you might try is to filter out specific industries. So this example would select all the data where the first argument was "SomeIndustry"

 someIndustryData = Select[data, First[#]=="SomeIndustry" &]

Once you have that data, you could select the second part of every pair

someIndustryData[[All,2]]

Of course, this might be a pain to do for all industries, so you can always use GroupBy:

GroupBy[data,First]

<| "Industry1" -> {....}, "Industry2" ->{...}, ..... |>
POSTED BY: Sean Clarke
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