Skip to main content
Question

Assign closest category number to a value

  • June 11, 2020
  • 1 reply
  • 5 views

katt
Supporter
Forum|alt.badge.img+12
  • Supporter
  • 41 replies

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.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

1 reply

daveatsafe
Safer
Forum|alt.badge.img+19
  • Safer
  • 1637 replies
  • June 11, 2020

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.