Aaron91204
Aaron91204

Reputation: 11

Adding Indexes to elements of a list in kdb

How can I add to each element of a list its index, i.e add 0 to the element at index 0, add 1 to the element at index 1 and so on.

My list is list1:

 q)list1:3+20?30

Upvotes: 0

Views: 842

Answers (1)

Rahul
Rahul

Reputation: 3969

Use 'til' and 'count' to generate indexes and add those to actual elements.

 q) list1 + til count list1

til count list1 will generate indexes of the list.

q) list1: 1 2 3
q) count list1  / 3
q) til count list1  / same as til count 3
q) 0 1 2

Upvotes: 2

Related Questions