(defn indicator
"
Returns a sequence of ones and zeros, where ones
are returned when the given predicate is true for
corresponding element in the given collection, and
zero otherwise.
Examples:
(use 'incanter.stats)
(indicator #(neg? %) (sample-normal 10))
;; return the sum of the positive values in a normal sample
(def x (sample-normal 100))
(sum (mult x (indicator #(pos? %) x)))
"
([pred coll]
(for [el coll] (if (pred el) 1 0))))
Comments top
No comments for indicator. Log in to add a comment.