cancel
Showing results forΒ 
Search instead forΒ 
Did you mean:Β 

sublist on an array

david_bieber
New Contributor
Hi KDB Group,

I am try to get a extract a subset of a list using sublist but it doesn't works for a list with size greater than 1 if I specifly sublist[start, length]

For instance if I want to extract the first 2 number from the list it works

2 sublist (1 2 3 4)
>> 1 2i
2 sublist ' (1 2 3 4; 5 6 7 😎
>> (1 2; 5 6)

However if I use the second argument it doesn't work
2 2 sublist (1 2 3 4)
>> 2 3i / works!
2 2 sublist ' (1 2 3 4; 5 6 7 😎
>> (1 2; 5 6)  / incorrect - was expecting (2 3; 6 7)


for larger list it returns an error
2 2 sublist ' (1 2 3 4; 5 6 7 8; 9 10 11 12)
>> '
length

of course I could use the take and drop
2# ' 1_ ' (1 2 3 4;5 6 7 8;9 10 11 12)
>> (2 3; 5 6; 10 11)

However I think it is probably more optimized and clearer code using sublist.

Can anyone help?

Thanks

David
2 REPLIES 2

david_demner
New Contributor
You need each-right (/:) not each both (')

2 2 sublist/: (1 2 3 4;5 6 7 😎

' can sometimes tell what you want to do but not here

From: David Bieber
Sent: Tuesday, June 14, 2016 13:05
To: Kdb+ Personal Developers
Reply To: personal-kdbplus@googlegroups.com
Subject: [personal kdb+] sublist on an array

Hi KDB Group,

I am try to get a extract a subset of a list using sublist but it doesn't works for a list with size greater than 1 if I specifly sublist[start, length]

For instance if I want to extract the first 2 number from the list it works

2 sublist(1234)
>>12i
2 sublist' (1 2 3 4; 5 6 7 😎
>> (1 2; 5 6)

However if I use the second argument it doesn't work
22 sublist(1234)
>>23i/ works!
22 sublist' (1 2 3 4; 5 6 7 😎
>> (1 2; 5 6)  / incorrect - was expecting (2 3; 6 7)


for larger list it returns an error
22 sublist' (1 2 3 4; 5 6 7 8; 9 10 11 12)
>> '
length

of course I could use the take and drop
2# ' 1_ ' (1 2 3 4;5 6 7 8;9 10 11 12)
>>(23;56;1011)

However I think it is probably more optimized and clearer code using sublist.

Can anyone help?

Thanks

David

--
You received this message because you are subscribed to the Google Groups "Kdb+ Personal Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email topersonal-kdbplus+unsubscribe@googlegroups.com.
To post to this group, send email to personal-kdbplus@googlegroups.com.
Visit this group at https://groups.google.com/group/personal-kdbplus.
For more options, visit https://groups.google.com/d/optout.

This e-mail message is intended to be received only by persons entitled to receive the confidential information it may contain. E-mail messages to clients of AquaQ Analytics may contain information that is confidential and legally privileged. Please do not read, copy, forward, or store this message unless you are an intended recipient of it. If you have received this message in error, please forward it to the sender and delete it completely from your computer system

Many thanks. Perfect. D