- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Select the 10 largest values of my table
Hi,
I would like to extract the ten largest values of my table.
How can I do ?
Is there a script associated ?
thanks for your help !
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Select the 10 largest values of my table
Two ways to do it:
Easy way:
dt << select where(:humidity >= humidity_mtx[10]);
Another way:
dt << select where(contains(humidity_mtx[1::10], :humidity));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Select the 10 largest values of my table
Here's one way to do it using the summarize command. Summarize yields the list of unique values but they're a list of character strings.
dt = open("$sample_data\bands data.jmp");
summarize(humidity_list = by(:Humidity));
n = nitems(humidity_list);
humidity_mtx = index(1, n);
for (i = 1, i <= n, i++,
humidity_mtx[i] = num(humidity_list[i]);
);
humidity_mtx = sort descending(humidity_mtx);
print(humidity_mtx[1::10]);
[105, 103, 100, 98, 96, 95, 94, 93, 92, 91]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Select the 10 largest values of my table
Thank you !
I have my ten values in this list but i would like now to select in a table, the lines which have a value in this list :
I tried : mytable<< Select Where(value in values_mtx);
but it doesnt work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Select the 10 largest values of my table
Two ways to do it:
Easy way:
dt << select where(:humidity >= humidity_mtx[10]);
Another way:
dt << select where(contains(humidity_mtx[1::10], :humidity));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Select the 10 largest values of my table
The original question may be answered in different ways depending of the objectives.
PMroz code successfully selects all rows of the 10 top levels (which means more than ten rows selected if several rows have the same value).
If you rather want to select exactly ten rows with the highest values (and possibly leaving tied values of the lowest top-ten levels behind) this approach could be used:
dt = open("$sample_data\Bands Data.jmp");
n=nrow(dt);
dt << select rows(loc(ranking(:humidity[1::n])>=n-10));
Here's an alternative that selects the percentage of rows (roughly) corresponding to the to the top ten rows, but here tied rows with the lowest value of the top 10 rows are included:
dt << select where(:humidity >= col quantile(:humidity, 1-10/n));
All three approaches here yields different results, but each may be right depending on the circumstances.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Select the 10 largest values of my table
Thank you very much PMroz and MS !