1
AutoLISP (Vanilla / Visual) / Re: most common value in a list (mode)
« Last post by hmspe on Today at 10:11:16 AM »Thanks, Lee.
Sorry, no time to look at code but what happens in the following situation?My most recent post will return 11. My understanding is that the mode would be undefined for your data set because there is not a single number with the highest count in the data set.
11, 11, 33, 33, 54
Should 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 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))