1.2.3-SNAPSHOT permalink Arrow_down_16x16

bind-rows

incanter.core

  • (bind-rows & args)
Returns the matrix resulting from concatenating the given matrices
and/or sequences by their rows. Equivalent to R's rbind.

Examples:
(def A (matrix [[1 2 3]
[4 5 6]
[7 8 9]]))

(def B (matrix [[10 11 12]
[13 14 15]]))

(bind-rows A B)

(bind-rows [1 2 3 4] [5 6 7 8])

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

(defn bind-rows
"   Returns the matrix resulting from concatenating the given matrices
    and/or sequences by their rows. Equivalent to R's rbind.

    Examples:
      (def A (matrix [[1 2 3]
                     [4 5 6]
                     [7 8 9]]))

      (def B (matrix [[10 11 12]
                      [13 14 15]]))

      (bind-rows A B)

      (bind-rows [1 2 3 4] [5 6 7 8])

"
  ([& args]
   (reduce
    (fn [A B]
      (cond
        (nil? (seq A))
          B
        (nil? (seq B))
          A
        (and (matrix? A) (matrix? B))
          (conj A B)
        (and (matrix? A) (coll? B))
          (conj A B)
        (and (coll? A) (matrix? B))
          (conj (matrix A (count A)) B)
        (and (coll? A) (coll? B))
          (conj (matrix A (count A)) (matrix B (count B)))
        :else
          (throw (Exception. "Incompatible types"))))
      args)))
Vars in incanter.core/bind-rows: and coll? cond conj count defn fn nil? reduce seq
Used in 0 other vars

Comments top

No comments for bind-rows. Log in to add a comment.