1.2.3-SNAPSHOT permalink Arrow_down_16x16

$order

incanter.core

  • ($order cols order)
  • ($order cols order data)
Sorts a dataset by the given columns in either ascending (:asc)
or descending (:desc) order. If used within a the body of
the with-data macro, the data argument is optional, defaulting
to the dataset bound to the variable $data.

Examples:

(use '(incanter core charts datasets))
(def iris (get-datset :iris))
(view ($order :Sepal.Length :asc iris))
(view ($order [:Sepal.Width :Sepal.Length] :desc iris))

(with-data (get-dataset :iris)
(view ($order [:Petal.Length :Sepal.Length] :desc)))

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:1722 top

(defn $order
  " Sorts a dataset by the given columns in either ascending (:asc)
    or descending (:desc) order. If used within a the body of 
    the with-data macro, the data argument is optional, defaulting
    to the dataset bound to the variable $data.

    Examples:

    (use '(incanter core charts datasets))
    (def iris (get-datset :iris))
    (view ($order :Sepal.Length :asc iris))
    (view ($order [:Sepal.Width :Sepal.Length] :desc iris))

    (with-data (get-dataset :iris)
      (view ($order [:Petal.Length :Sepal.Length] :desc)))
          
  "
  ([cols order]
     ($order cols order $data))
  ([cols order data]
     (let [key-cols (if (coll? cols) cols [cols])
	   key-fn (fn [row] (into [] (map #(map-get row %) key-cols)))
	   comp-fn (if (= order :desc)
		     (comparator (fn [a b] (pos? (compare a b))))
		     compare)]
       (dataset (col-names data) (sort-by key-fn comp-fn (:rows data))))))
Vars in incanter.core/$order: defn let sort-by
Used in 0 other vars

Comments top

No comments for $order. Log in to add a comment.