./
pp_quartile.pro
Routines
top source pp_quartile
result = pp_quartile(iarr, quart [, cut=cut] [, nan=nan] [, index=index] [, sort=sort])
Given an array iarr, returns the value(s) in the array that correspond to
the given quartile(s). If cut
is set, instead of the quartile values, returns
a copy of the array, with minimum and maximum values given by the two quartiles provided.
Parameters
- iarr in required
The array for which the quartile(s) will be calculated.
- quart in required
The desired quartile(s). It can be a scalar or an array.
Keywords
- cut in optional
If set,
quart
must be a two-elementarray
. Instead of returning quartile values, the function will return a copy of the array, with all values below the low quartile (the first element inquart
) will be set to the array's value at that quartile, and all values above the high quartile (the second element inquart
) will be set to the value of the high quartile.- nan in optional
If the array contains non-finite values (NaN or Infinity), this must be set so that the quartiles are correctly calculated. By default, it is set. Setting nan to zero saves time, but if the array contains non-finite values and nan is zero, incorrect results may be returned.
- index out optional
An array with the index in
s
corresponding to the quartiles selected. Useful to obtain indices iniarr
that match some quartile level. See example- sort out optional
An array with the indices to sort the input array: s=sort(iarr)
Examples
Create an array with 10 values between 0 and 9 and check on some of its quartiles:
a=reverse(dindgen(10))
print,pp_quartile(a,[0.2d0,0.8d0])
; 2.0000000 8.0000000
print,pp_quartile(a,[0.2d0,0.8d0],/cut)
; 8.0000000 8.0000000 7.0000000 6.0000000 5.0000000
; 4.0000000 3.0000000 2.0000000 2.0000000 2.0000000
Obtain the elements of a which are below the 50% quartile:
a_50=pp_quartile(a,0.5d0,index=ind,sort=s)
print,a[s[0:ind]]
; 0.0000000 1.0000000 2.0000000 3.0000000 4.0000000 5.0000000
Author information
- Author:
Paulo Penteado (http://www.ppenteado.net ), Jan/2016
Statistics
Lines: | 14 lines |
Cyclomatic complexity: | 4 |
Modified cyclomatic complexity: | 4 |
File attributes
Modification date: | Wed Jun 29 22:15:28 2016 |
Lines: | 14 |
Docformat: | rst rst |