KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums kdb+ Accessing the last element of List of List

  • Accessing the last element of List of List

    Posted by ekallivrousis on December 8, 2021 at 12:00 am
    x:(`Col1;12;.z.Z) y:(x;x;x) 
    //add gtime of last element to end of x 
    x,@[gtime;last x;0Np] 
    //How do i do this for y?

    So i think i did x correctly unless theres a better way. But how would i handle y? I want to append to end of each list in y.

    ekallivrousis replied 3 months, 2 weeks ago 2 Members · 3 Replies
  • 3 Replies
  • soheir

    Member
    December 8, 2021 at 12:00 am

    This might be what you’re looking for then

    q) x1:(`Col1;12;.z.Z) 
    q) x2:(`Col1;12;`ERROR) 
    q) show y:(x1;x1;x1;x2) 
    `Col1 12 2021.12.08T17:46:26.162 
    `Col1 12 2021.12.08T17:46:26.162 
    `Col1 12 2021.12.08T17:46:26.162 
    `Col1 12 `ERROR 
    q) {x,@[gtime;last x;0Np]}each y 
    `Col1 12 2021.12.08T17:46:26.162 2021.12.08T17:46:26.162 
    `Col1 12 2021.12.08T17:46:26.162 2021.12.08T17:46:26.162 
    `Col1 12 2021.12.08T17:46:26.162 2021.12.08T17:46:26.162 
    `Col1 12 `ERROR 0Np

     

  • soheir

    Member
    December 8, 2021 at 12:00 am

    Hey @ekallivrousis – is this what you’re trying to do?

    q)x:(`Col1;12;.z.Z)
    q)y:(x;x;x)
    
    `Col1 12 2021.12.08T17:33:36.400
    `Col1 12 2021.12.08T17:33:36.400
    `Col1 12 2021.12.08T17:33:36.400
    q)y,'gtime .z.P
    
    `Col1 12 2021.12.08T17:33:36.400 2021.12.08D17:33:47.617397000
    `Col1 12 2021.12.08T17:33:36.400 2021.12.08D17:33:47.617397000
    `Col1 12 2021.12.08T17:33:36.400 2021.12.08D17:33:47.617397000

    Or are you looking to use the last item of each list of y (list of lists) as an input to gtime ?

  • ekallivrousis

    Member
    December 8, 2021 at 12:00 am

    Close, i want it to be in protected eval @[], also i dont want to convert current .z.P i want to convert the last col of each list in y. I bold the column below that i want to use

    `Col1 12 2021.12.08T17:33:36.400
    `Col1 12 2021.12.08T17:33:36.400
    `Col1 12 2021.12.08T17:33:36.400

Log in to reply.