0 Members and 2 Guests are viewing this topic.
;; Count Items - Lee Mac;; Returns a list of dotted pairs detailing the number of;; occurrences of each item in a supplied list.(defun LM:CountItems ( l / c x ) (if (setq x (car l)) (progn (setq c (length l) l (vl-remove x (cdr l)) ) (cons (cons x (- c (length l))) (LM:CountItems l)) ) ))
(LM:CountItems '("A" "B" "B" "B" "C" "C" "D" "E" "E" "E" "E"))=> (("A" . 1) ("B" . 3) ("C" . 2) ("D" . 1) ("E" . 4))(LM:CountItems '(1 2 3 3 3 4 5 6 6 7 8 8 8 8))=> ((1 . 1) (2 . 1) (3 . 3) (4 . 1) (5 . 1) (6 . 2) (7 . 1) (8 . 4))
Just use count items by Lee Mac
Sorry, no time to look at code but what happens in the following situation?11, 11, 33, 33, 54Should be: (11, 33)
;; Count Items - Lee Mac ;;; Returns a list of dotted pairs detailing the number of ;;; occurrences of each item in a supplied list. ;(defun CountItems ( l / x c ) (if (setq x (car l)) (progn (setq c (length l) l (vl-remove x (cdr l)) ) (cons (cons x (- c (length l))) (CountItems l)) ) ) )(defun mode (l) (setq l (vl-sort (countitems l) '(lambda (a b) (> (cdr a) (cdr b))))) )
_$ (mode '(1 2 3 3 3 3 4 5 6 6 7 8 8 8 8))((3 . 4) (8 . 4) (6 . 2) (1 . 1) (2 . 1) (4 . 1) (5 . 1) (7 . 1))
The mode is the most common number that appears in your set of data. To find the mode count how often each number appears and the number that appears the most times is the mode.
Mode: The most frequent number—that is, the number that occurs the highest number of times.