On Tue, Apr 13, 2010 at 4:48 AM, Glen Rubin <rubing...@gmail.com> wrote:
> I want to create an average sequence such that all of the first
> elements are averaged, all of the second elements, etc....

Sounds like you want a traspose function. Here you go:

(defn transpose [m]
  (apply map list m))

Example:

user=> (def sequences '((123) (4 5 6) (7 8 9)))
#'user/sequences
user=> (transpose sequences)
((1 4 7) (2 5 8) (3 6 9))
user=> (map #(reduce + %) (transpose sequences))
(12 15 18)

Or in one line if you don't want a transpose function:

user=> (map #(reduce + %) (apply map list sequences))
(12 15 18)

Disclaimer: I have not had my morning coffee yet, sorry if I
misunderstood your intention.

Michael

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

To unsubscribe, reply using "remove me" as the subject.

Reply via email to