Since the position must be an integer, we need to ensure that the returned value does not contain any decimals using the $floor operator. The result of this multiplication will be the position within the vector where we will find the value of the quantile. For example, if we want to calculate the median we will have to multiply it by 0.5, for the first quartile by 0.25, and so on. The size of the vector will have to be multiplied by the value of the quantile of interest. Obviously it was possible to extract this information during the grouping operation using the $sum operator. Using the $size operator we will calculate the size of the value vector. The calculation of quantiles will be done by some mathematical and vector manipulation operators. In our example we will have to order the price field in ascending order as shown below. For each of them it is mandatory to insert the direction of the sort (1 ascending, -1 descending). Similarly to the sort function used to sort the results of the find, the $sort operator requires a sorted document of the attributes on which to perform the sort. The first step is to sort the data in the collection.We will use the $sort operator. Specifically, we will calculate the median, the first and fourth quartiles, and the 95th percentile.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |