mean(v) = sum(v)/length(v) #or, the second one is what was expected from you, the one above is provided to see other ways Julia offers to deal with the same problem function mean(v) n = length(v) s = 0 for i in 1:n s += v[i] end mu = s/n return mu end