1.2.3-SNAPSHOT Arrow_down_16x16

categorical-var

incanter.core

  • (categorical-var & args)
Returns a categorical variable based on the values in the given collection.
Equivalent to R's factor function.

Options:
:data (default nil) factors will be extracted from the given data.
:ordered? (default false) indicates that the variable is ordinal.
:labels (default (sort (into #{} data)))
:levels (range (count labels))

Examples:
(categorical-var :data [:a :a :c :b :a :c :c])
(categorical-var :labels [:a :b :c])
(categorical-var :labels [:a :b :c] :levels [10 20 30])
(categorical-var :levels [1 2 3])

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source incanter/core.clj:2114 top

(defn categorical-var
" Returns a categorical variable based on the values in the given collection.
  Equivalent to R's factor function.

  Options:
    :data (default nil) factors will be extracted from the given data.
    :ordered? (default false) indicates that the variable is ordinal.
    :labels (default (sort (into #{} data)))
    :levels (range (count labels))

  Examples:
    (categorical-var :data [:a :a :c :b :a :c :c])
    (categorical-var :labels [:a :b :c])
    (categorical-var :labels [:a :b :c] :levels [10 20 30])
    (categorical-var :levels [1 2 3])

"
  ([& args]
   (let [opts (when args (apply assoc {} args))
         data (:data opts)
         ordered? (if (false? (:ordered? opts)) true false)
         labels (or (:labels opts)
                    (if (nil? data)
                      (:levels opts)
                      (sort (into #{} data))))
         levels (or (:levels opts) (range (count labels)))]
    {:ordered? ordered?
     :labels labels
     :levels levels
     :to-labels (apply assoc {} (interleave levels labels))
     :to-levels (apply assoc {} (interleave labels levels))})))
Vars in incanter.core/categorical-var: defn let
Used in 0 other vars

Comments top

No comments for categorical-var. Log in to add a comment.