Choose Language Hide Translation Bar
Level III

## How do get the position by fuzzy matching?

``````dt=Open("\$SAMPLE_DATA\Big Class.jmp");
dt<<Sort(By(4),Order(Ascending),replace table);``````

In ascending order of height, how do I get the row number of a value that does not appear in the height column that is closest to the height less than this value in the height column?

For example, this value is 54.

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Staff (Retired)

## Re: How do get the position by fuzzy matching?

This might work, but LocSorted has some edge cases, especially at the lower end, that might make it hard to use. Read the doc and decide what you need to do for the too-small and too-big case. I think it might always return the first row of the set of values, but that isn't documented.  @XanGregg

``````dt=Open("\$SAMPLE_DATA\Big Class.jmp");
dt<<Sort(By(4),Order(Ascending),replace table);
vector = dt:height<<getasmatrix;
position = loc sorted(vector,[54])[1];
show(dt[position,0]);``````

dt[position,0] = {"LILLIE", 12, "F", 52, 64};

Craige
2 REPLIES 2
Highlighted
Staff (Retired)

## Re: How do get the position by fuzzy matching?

This might work, but LocSorted has some edge cases, especially at the lower end, that might make it hard to use. Read the doc and decide what you need to do for the too-small and too-big case. I think it might always return the first row of the set of values, but that isn't documented.  @XanGregg

``````dt=Open("\$SAMPLE_DATA\Big Class.jmp");
dt<<Sort(By(4),Order(Ascending),replace table);
vector = dt:height<<getasmatrix;
position = loc sorted(vector,[54])[1];
show(dt[position,0]);``````

dt[position,0] = {"LILLIE", 12, "F", 52, 64};

Craige
Highlighted
Staff

## Re: How do get the position by fuzzy matching?

Craige is correct: if there is more than one matching value, the index of the first matching value is returned.
Article Labels

There are no labels assigned to this post.