1

I want to extract the last four elements of a vector in DolphinDB. For example:

v=1..9
v[5:9]

Output:

enter image description here

I'd like to find an easier method to achieve this, so I tried the following method:

l=size(v)
v[l-4:l]

But the result is not as expected. Does anyone know how to solve this problem?

molddd123
  • 297
  • 6

1 Answers1

1

This is due to operator precedence. You need to add parentheses around 1-4:

l=size(v)
v[(l-4):l]

Or you can try a more efficient method:

v.tail(4)