# Use FindClusters with the following elements structure?

GROUPS:
 Each X-element below is a pair that has a label and xy-point.How do I cluster the X-elements using the distance between points? The code below balks because the data structure is incompatible with FindClusters. If X had points only then everything works. But here I must maintain the structure of X-elements for later use.I don't see a FindClusters option that would allow this. If another function works then I've missed it. Thanks.Bruce X = {{"a", {12, 30}}, {"b", {13, 31}}, {"c", {100, 102}}, {"d", {101, 103}}}; FindClusters[X, DistanceFunction -> (EuclideanDistance[Last@#1, Last@#2] &)] Error message is "FindClusters does not support this type of data"
1 year ago
5 Replies
 Sander Huisman 2 Votes Please have a look at the documentation next time:You can clearly see that $e_i$ are the values on which the distance is based and $v_i$ the return values. So it is just a matter of reshaping your input: X = {{"a", {12, 30}}, {"b", {13, 31}}, {"c", {100, 102}}, {"d", {101, 103}}}; input = Rule[#2, {##}] & @@@ X FindClusters[input] 
1 year ago
 Bruce Colletti 1 Vote Thank you for the reply, Sander. Your solution uses constructs with which I'm unfamiliar and I will study it.I did study the documentation in advance and saw what you pointed out. None of the documentation's examples (that used the e->v construct) returned what I needed and recognized. Neither did Mathematica Stack Exchange and so I turned to Wolfram Community. As usual, the response was excellent and informative.
 note that: input = Rule[#2, {##}] & @@@ X can be rewritten as: input = Table[i[[2]] -> i,{i,X}] or input = #[[2]] -> #& /@ X or input = MapThread[#2 -> {##} &, Transpose[X]] or input = Reap[Do[Sow@Rule[i[[2]], i], {i, X}]][[2, 1]] or input = Thread[Rule[X[[All, 2]], X]] or .........The last one should be one of the faster ones I presume...