1.2.3-SNAPSHOT Arrow_down_16x16
  • ($map fun col-keys data)
  • ($map fun col-keys)
This function returns a sequence resulting from mapping the given function over
the value(s) for the given column key(s) of the given dataset.
Like other '$*' functions, it will use $data as the default dataset
if none is provided, where $data is set using the with-data macro.

Examples:

(use '(incanter core datasets))
(def cars (get-dataset :cars))

($map "speed" (fn [s] (/ s)) cars)
($map ["speed" "dist"] (fn [s d] (/ s d)) cars)

($map (fn [s] (/ s)) :speed cars)
($map (fn [s d] (/ s d)) [:speed :dist] cars)

(map (fn [s d] (/ s d)) ($ :speed cars) ($ :speed cars))

(with-data (get-dataset :cars)
(view ($map (fn [s] (/ s)) :speed))
(view ($map (fn [s d] (/ s d)) [:speed :dist])))

;; calculate the speed to dist ratio and append as new column to dataset
(with-data (get-dataset :cars)
(conj-cols $data ($map (fn [s d] (/ s d)) [:speed :dist])))


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

(defn $map 
  "This function returns a sequence resulting from mapping the given function over
    the value(s) for the given column key(s) of the given dataset.
    Like other '$*' functions, it will use $data as the default dataset
    if none is provided, where $data is set using the with-data macro. 

  Examples:

    (use '(incanter core datasets))
    (def cars (get-dataset :cars))

    ($map \"speed\" (fn [s] (/ s)) cars)
    ($map [\"speed\" \"dist\"] (fn [s d] (/ s d)) cars)

    ($map (fn [s] (/ s)) :speed cars)
    ($map (fn [s d] (/ s d)) [:speed :dist] cars)

    (map (fn [s d] (/ s d)) ($ :speed cars) ($ :speed cars))

    (with-data (get-dataset :cars)
      (view ($map (fn [s] (/ s)) :speed))
      (view ($map (fn [s d] (/ s d)) [:speed :dist])))

    ;; calculate the speed to dist ratio and append as new column to dataset
    (with-data (get-dataset :cars)
      (conj-cols $data ($map (fn [s d] (/ s d)) [:speed :dist])))


"
  ([fun col-keys data]
     (let [rows (:rows data)]
       (if (coll? col-keys)
         (map (fn [row] (apply fun (map (fn [k] (map-get row k)) col-keys))) (:rows data))
         (map (fn [row] (fun (map-get  row col-keys))) (:rows data)))))
  ([fun col-keys]
     ($map fun col-keys $data)))
Vars in incanter.core/$map: apply coll? defn fn let map
Used in 0 other vars

Comments top

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