| **Navigation:**  [[templates.htm|Templates]] > Guide to all Templates > [[additional libraries and templates.htm|Additional Libraries and Templates]] > Statistics Library >====== FREQUENCY (frequency count of an item in a set) ====== | [[factorial factorial of a number .htm|{{btn_prev_n.gif|Previous page}}]][[additional libraries and templates.htm|{{btn_home_n.gif|Return to chapter overview}}]][[lowerquartile lower quartile value of a set .htm|{{btn_next_n.gif|Next page}}]] | | || **FREQUENCY**(//dataset,searchvalue//) {{blk2blue.jpg|blk2blue.jpg}} | **FREQUENCY** | Counts the number of instances of a particular value within a numeric set. | | //dataset// | The label of a QUEUE with its first component field defined as a REAL. | | //searchvalue// | A numeric constant or variable containing the value to search for in the QUEUE. | **FREQUENCY **counts the number of instances of a particular value (//searchvalue//) within a numeric set (//dataset//). The function operates on the numeric set defined by all the entries in the first component of the designated QUEUE (//dataset//). For example, given the data set: [1,2,2,3,4,5] and the search value 2, the function would return a frequency count of 2. {{notebox.jpg|NoteBox.jpg}} The passed data set does not have to be sorted. The function copies the passed set. The passed data set is unchanged. **Return DataType:**     REAL **Example:** **StatSetX  QUEUE,PRE()** **X          REAL** **          END** **FrequencyOfX REAL** **SearchValue  REAL(1)** **CODE** **    FREE(StatSetX)                   !free the QUEUE** **    CLEAR(STADAT:RECORD)             !clear the record buffer** **    STADAT:Id = STA:Id               !prime the record buffer** **    STADAT:ItemNumber = 1** **    SET(STADAT:KeyIdItemNumber,STADAT:KeyIdItemNumber !position file pointer** **    LOOP                             !load the QUEUE** **      NEXT(StatisticsData)           !read next record** **      IF ERRORCODE() OR STADAT:Id NOT = STA:Id** **        BREAK** **      ELSE** **        StatSetX:X = STADAT:X        !load the QUEUE buffer** **        ADD(StatSetX)                !add to the QUEUE** **      END** **    END** **   FrequencyOfX = FREQUENCY(StatSetX,SearchValue) !call FREQUENCY to search Q**