Apologies - this probably should be in jchat.

In KDB (Q), you can revert to K with \

Then you can calculate a mean in similar fashion to
APL or J.  The symbols for the primitives are slightly
different but very like in execution,

K's  !  ~  J's  i.  ~  APL's iota .
K's  #  ~  J's  #   ~  APL's rho .

Here are three lines from a kdb session:

q)\   / escape to K from Q
   {(+/x)%#x}[!10]     / mean
4.5

K's functions are a bit like Dyalog APL's dynamic
functions,  J's explicit functions or Pari-GP's
user-defined functions.

til and count are Q cover functions for K's ! and # .
eg the file q.k contains this definition:

    til:{$[-6h=@x;!x;'`type]}

The fine details escape me,  but you can see ! x
in there!

Mike

PS - median is not the same as mean.

On 16/01/2012 8:31 PM, mikel paternain wrote:
> Here a first aproximation.
>
> - define a list(unidimensional vector) For example the firs ten integer 
> numbers. q) is the prompt in Q system.
> q) L: 1 2 3 4 5 6 7 8 9 10
>
> - next, sum all integers
> q) suminteger: sum L
>
> - now, count elements of L
> number: count L
>
> -and to end, compute the mean
> q) median: suminteger%number
>
> Another way is
>
> q) (sum L)%(count L)
> 5.5
>
> In Q the function to obtain integers is til
>
> q) til 10
> 0 1 2 3 4 5 6 7 8 9
>
> Best,
>
> Mikel
>
>
>>> Message: 1
>> Date: Mon, 16 Jan 2012 17:11:09 +0100
>> From: Kim Kuen Tang<kuent...@vodafone.de>
>> Subject: Re: [Jprogramming] Advantages of J over Q (aka K4/Kdb+)
>> To: Programming forum<programming@jsoftware.com>
>> Message-ID:<4f144c1d.90...@vodafone.de>
>> Content-Type: text/plain; charset=UTF-8; format=flowed
>>
>>
>> I tried to calculate the mean in K using tacit programming.
>> (+/%# ) !10
>> But it is not working. Can you show how to program it in K?
>>
>                                       
> ----------------------------------------------------------------------
> For information about J forums seehttp://www.jsoftware.com/forums.htm
>


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to