Ok Tim,
this is what I want but imagine..
; ; ; 48.00 ;
; ; ; 32.50 ;
; ; ; 15.00 ;
; ; ; 59.40 ;
; 47.80 ; ; ;
That some field of colum don't have any numbers
Your first method fails because some field at position 3 are not feed:
let s=0|g/\d/let s+=str2float(split(getline('.'), ';')[3])
2011/10/12 Tim Chase <[email protected]>
> On 10/12/11 12:00, niva wrote:
>
>> 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.
>>
>
> To sum column 4 (zero-based, 3), you can use:
>
> :let s=0|g/\d/let s+=str2float(split(getline('.'**), ';')[3])
>
> which will set "s" to the sum of the given column. If for some reason you
> don't have N columns in each row (fewer than N-1 delimiters), you might have
> to change that to
>
> :let s=0|g/\d/let s+=str2float(get(split(**getline('.'), ';'), 3, 0)
>
> to default the column-value to 0 instead of indexing too far into the
> results of split().
>
> Note that this has the usual accuracy issues one normally finds with floats
> as mentioned at
>
> :help floating-point-precision
>
> -tim
>
>
>
>
> --
> 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<http://www.vim.org/maillist.php>
>
--
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