Hi Christian,
On 17 Jul 2011, Christian Moe wrote:
> Hi,
>
> Time calculations don't seem to work with vsum (or vmean).
>
>
> | Time |
> |---------|
> | 1:06:00 |
> | 0:52:30 |
> | 2:00:00 |
> |---------|
> | 3 |
> #+TBLFM: @5$1=vsum(@I..@II);T
>
>
> Am I doing something wrong?
Yes, `vsum' works just on numbers, not times.
> Could this be made to work?
Here's a elisp function that does what you want (assuming it's
hours:minutes:seconds -- if not tweak the numbers):
#+begin_src elisp
(defun h-m-s-vsum (times)
(loop for (h m s) in (mapcar (lambda (time)
(mapcar #'string-to-int
(split-string time ":" 'omit-nulls)))
times)
collect (+ (* 3600 h) (* 60 m) s) into seconds
finally (return (let* ((second-sum (apply #'+ seconds))
(seconds (let ((s (% second-sum 60)))
(decf second-sum s)
s))
(minutes (let ((m (% second-sum 3600)))
(decf second-sum m)
(truncate (/ m 60))))
(hours (/ second-sum 3600)))
(format "%s:%s:%s" hours minutes seconds)))))
#+end_src elisp
The table has to be
| Time |
|---------|
| 1:06:00 |
| 0:52:30 |
| 2:00:00 |
|---------|
| 3:58:30 |
#+TBLFM: @5$1='(h-m-s-vsum '(@I..@II))
Hope that helps.
Maybe there is an easier way. I hope there is ;)
Michael