cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing the last element of List of List

ekallivrousis
New Contributor III
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. 

1 ACCEPTED SOLUTION

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

 

View solution in original post

3 REPLIES 3

soheir
New Contributor II
New Contributor II

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
New Contributor III

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

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

 

View solution in original post