1.2.3-SNAPSHOT Arrow_down_16x16
  • ($ cols)
  • ($ cols data)
  • ($ rows cols data)
An alias to (sel (second args) :cols (first args)). If given only a single argument,
it will use the $data binding for the first argument, which is set with
the with-data macro.

Examples:
(use '(incanter core stats charts datasets))

(def cars (get-dataset :cars))
($ :speed cars)


(with-data cars
(def lm (linear-model ($ :dist) ($ :speed)))
(doto (scatter-plot ($ :speed) ($ :dist))
view
(add-lines ($ :speed) (:fitted lm))))

;; standardize speed and dist and append the standardized variables to the original dataset
(with-data (get-dataset :cars)
(view (conj-cols $data
(sweep (sweep ($ :speed)) :stat sd :fun div)
(sweep (sweep ($ :dist)) :stat sd :fun div))))

(with-data (get-dataset :iris)
(view $data)
(view ($ [:Sepal.Length :Sepal.Width :Species]))
(view ($ [:not :Petal.Width :Petal.Length]))
(view ($ 0 [:not :Petal.Width :Petal.Length])))


(use 'incanter.core)
(def mat (matrix (range 9) 3))
(view mat)
($ 2 2 mat)
($ [0 2] 2 mat)
($ :all 1 mat)
($ 1 mat)
($ [:not 1] mat)
($ 0 :all mat)
($ [0 2] [0 2] mat)
($ [:not 1] [:not 1] mat)
($ [:not 1] :all mat)
($ [0 2] [:not 1] mat)
($ [0 2] [:not 1 2] mat)
($ [0 2] [:not (range 2)] mat)
($ [:not (range 2)] [0 2] mat)

(with-data mat
($ 0 0))
(with-data mat
($ [0 2] 2 mat))
(with-data mat
($ :all 1))
(with-data mat
($ [0 2] [0 2]))
(with-data mat
($ [:not 1] :all))
(with-data mat
($ [0 2] [:not 1]))


(use 'incanter.datasets)
(view (get-dataset :cars))
($ (range 5) 0 (get-dataset :cars))
($ (range 5) :all (get-dataset :cars))
($ :all (range 2) (get-dataset :cars))

($ (range 5) :dist (get-dataset :cars))
($ [:not (range 5)] 0 (get-dataset :cars))
($ [:not 0 1 2 3 4] 0 (get-dataset :cars))
(with-data (get-dataset :cars)
($ 0 :dist))

(with-data (get-dataset :hair-eye-color)
(view $data)
(view ($ [:not :gender])))


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

(defn $ 
"An alias to (sel (second args) :cols (first args)). If given only a single argument,
  it will use the $data binding for the first argument, which is set with
  the with-data macro.

  Examples:
    (use '(incanter core stats charts datasets))

    (def cars (get-dataset :cars))
    ($ :speed cars)

    
    (with-data cars
      (def lm (linear-model ($ :dist) ($ :speed)))
      (doto (scatter-plot ($ :speed) ($ :dist))
        view
        (add-lines ($ :speed) (:fitted lm))))

    ;; standardize speed and dist and append the standardized variables to the original dataset
    (with-data (get-dataset :cars)
      (view (conj-cols $data 
                       (sweep (sweep ($ :speed)) :stat sd :fun div)
                       (sweep (sweep ($ :dist)) :stat sd :fun div))))

    (with-data (get-dataset :iris)
      (view $data)
      (view ($ [:Sepal.Length :Sepal.Width :Species]))
      (view ($ [:not :Petal.Width :Petal.Length]))
      (view ($ 0 [:not :Petal.Width :Petal.Length])))


     (use 'incanter.core)
     (def mat (matrix (range 9) 3))
     (view mat)
     ($ 2 2 mat)
     ($ [0 2] 2 mat)
     ($ :all 1 mat)
     ($ 1 mat)
     ($ [:not 1] mat)
     ($ 0 :all mat)
     ($ [0 2] [0 2] mat)
     ($ [:not 1] [:not 1] mat)
     ($ [:not 1] :all mat)
     ($ [0 2] [:not 1] mat)
     ($ [0 2] [:not 1 2] mat)
     ($ [0 2] [:not (range 2)] mat)
     ($ [:not (range 2)] [0 2] mat)

     (with-data mat 
       ($ 0 0))
     (with-data mat 
       ($ [0 2] 2 mat))
     (with-data mat 
       ($ :all 1))
     (with-data mat 
       ($ [0 2] [0 2]))
     (with-data mat 
       ($ [:not 1] :all))
     (with-data mat 
       ($ [0 2] [:not 1]))


     (use 'incanter.datasets)
     (view (get-dataset :cars))
     ($ (range 5) 0 (get-dataset :cars))
     ($ (range 5) :all (get-dataset :cars))
     ($ :all (range 2) (get-dataset :cars))

     ($ (range 5) :dist (get-dataset :cars))
     ($ [:not (range 5)] 0 (get-dataset :cars))
     ($ [:not 0 1 2 3 4] 0 (get-dataset :cars))
     (with-data (get-dataset :cars)
       ($ 0 :dist))

     (with-data (get-dataset :hair-eye-color)
       (view $data)
       (view ($ [:not :gender])))


"
  ([cols] 
     ($ :all cols $data))
  ([cols data] 
     (cond
       (nil? data) 
         ($ :all cols $data)
       (or (matrix? data) (dataset? data))
         ($ :all cols data)
       :else ;; data is actually a col index and cols is a row index
         ($ cols data $data)))
  ([rows cols data]
     (let [except-rows? (and (vector? rows) (= :not (first rows)))
	   except-cols? (and (vector? cols) (= :not (first cols)))
	   _rows (if except-rows?
		   (if (coll? (second rows))
		     (conj [:except-rows] (second rows))
		     (conj [:except-rows] (rest rows)))		     
		   [:rows rows])
	   _cols (if except-cols?
		   (if (coll? (second cols)) 
		     (conj [:except-cols] (second cols))
		     (conj [:except-cols] (rest cols)))
		   [:cols cols])
	   args (concat _rows _cols)]
       (apply sel data args))))
Vars in incanter.core/$: apply cond defn let nil? or
Used in 0 other vars

Comments top

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