Question

Assign closest category number to a value

  • 11 June 2020
  • 1 reply
  • 0 views

Badge +8

Hello, I have three records: 1.07, 2.34 and 4.81 and I have 5 different categories:

categoryvalueA0.65B2.55C3.85D4.75E7.95 I want to assign a category to each of my three records. The category assigned should be the one with the value closest to the record.

For record 1.07 it should be category A, for 2.34 it should be B and for 4.81 it should be D. How can the assignment be done automatically? What transformer to use? thx.


1 reply

Userlevel 2
Badge +17

Hi @katt,

The easiest method would be to use the AttributeRangeMapper, and set the ranges to the midpoints between the category values.

If you are getting your categories from an external source (ie. Excel), there is a slightly more complex method that will also give you good results. Use VertexCreators to create points from records and categories, where you set X to the value and Y to 0. Next, use the NeighborFinder transformer with the records sent to Base and the categories sent to Candidates. Enable Merge Attribute in the NeighborFinder to transfer the category to the record.

 

Reply