Hi niva!

On Mi, 12 Okt 2011, niva wrote:

> Hi
> 
> I have some data organized by column in a buffer like that :
> 
> 
>  ;               ;                 ; 48.00             ;
>  ;               ;                 ; 32.50             ;
>  ;               ;                 ; 15.00             ;
>  ;               ;                 ; 59.40             ;
>  ; 47.80         ;                 ;                   ;
>  ; 10.90         ;                 ;                   ;
> 
> 
>  ; 12.38         ;                 ;                   ;
> 
>  ;                  ;                 ; 35.65          ;
>  ; 10.90         ;                 ;                   ;
>  ; 29.99         ;                 ;                   ;
>  ;                  ;                 ; 342.57        ;
>  ;                  ;                 ; 400.00        ;
> 
> I would like to got the most faster method that sum each column like
> done in Excel by SUM() function.

fu! Sum(col)
    let fields=map(getline(1,'$'), 'split(v:val, ";")[a:col]')
    call filter(fields, 'str2nr(v:val)')
    return eval(join(fields, '+'))
endfu

com -nargs=1 Sum :call Sum(<args>)

This should be pretty fast. But it might be faster to use an explicit 
loop and not to use filter() and map() functions. 

Any way, You can also use my csv filetype plugin 
http://www.vim.org/scripts/script.php?script_id=2830
, which also defines the :SumCol command, which basically does the above 
for you (plus some more configuration and error handling, so this will 
be slower).


regards,
Christian
-- 
Alle Stärke liegt innen, nicht außen.
                -- Jean Paul (eig. Johann Paul Friedrich Richter)

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to