I am a beginner to functional programming and Clojure programming language and I’m resorting to
recur pretty much for everything. I have a dataset in csv, imported as a map. I have extracted the info I need to use as vectors. Each column is a vector
[1 5 10 8 3 2 1 ...] and I want to calculate the mean of each column. I wrote the following function:
(defn mean "Calculate the mean for each column" ([columns] (mean columns )) ([columns means] (if (empty? columns) means (recur (rest columns) (conj means (float (/ (reduce + (first columns)) (count (first columns))))))))) ;; Calcule the mean for the following vectors (mean [[1 2 3] [1 2 3] [1 2 3]]) ; => [2.0 2.0 2.0]
Is this a functional way of solving this problem?