_ Drop¶
Drop items from a list, entries from a dictionary or columns from a table.
x _ y _[x;y]
_(drop) is a multithreaded primitive.
Drop leading or trailing items¶
Where
xis an int atomya list or dictionary
returns y without the first or last x items.
q)5_0 1 2 3 4 5 6 7 8 /drop the first 5 items
5 6 7 8
q)-5_0 1 2 3 4 5 6 7 8 /drop the last 5 items
0 1 2 3
q)1 _ `a`b`c!1 2 3
b| 2
c| 3
Drop from a string¶
q)b:"apple: banana: cherry"
q)(b?":") _ b / find the first ":" and remove the prior portion of the sentence
": banana: cherry"
Drop selected items¶
Where
xis a list or dictionaryyis an index or key ofx
returns x without the items or entries at y.
q)0 1 2 3 4 5 6 7 8_5 /drop the 5th item
0 1 2 3 4 6 7 8
q)(`a`b`c!1 2 3)_`a /drop the entry for `a
b| 2
c| 3
Drop keys from a dictionary¶
Where
xis an atom or vector of keys toyyis a dictionary
returns y without the entries for x.
Q for Mortals: ยง5. Dictionaries
Dropping dictionary entries with integer arguments
With dictionaries, distinguish the roles of integer arguments to _drop_.
<div class="peachq-example" markdown="1">
```q
q)d:100 200!\`a\`b
q)1 _ d /drop the first entry
200| b
q)d _ 1 /drop where key=1
100| a
200| b
q)d _ 100 /drop where key=100
200| b
q)enlist[1] _ d /drop where key=1
100| a
200| b
q)enlist[100] _ d /drop where key=100
200| b
q)100 _ d /drop first 100 entries
```
<a class="peachq-repl-link" href="../../../repl?code=d%3A100+200%21%5C%60a%5C%60b%0A1+_+d++++++++++++%2Fdrop+the+first+entry%0Ad+_+1++++++++++++%2Fdrop+where+key%3D1%0Ad+_+100++++++++++%2Fdrop+where+key%3D100%0Aenlist%5B1%5D+_+d++++%2Fdrop+where+key%3D1%0Aenlist%5B100%5D+_+d++%2Fdrop+where+key%3D100%0A100+_+d++++++++++%2Fdrop+first+100+entries&title=Drop+keys+from+a+dictionary&example=docs%2Fref%2Fdrop.md%3A5" target="_blank" rel="noopener noreferrer" aria-label="Open in REPL (new tab)" title="Open in REPL (new tab)"><svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M8 5v14l11-7z"/></svg></a>
</div>
Drop columns from a table¶
Where
xis a symbol vector of column namesyis a table
returns y without columns x.
q)t:([]a:1 2 3;b:4 5 6;c:`d`e`f)
q)`a`b _ t
c
-
d
e
f
q)t _ `a`b
'type
q)`a _ t
'type
q)t _ `a
'type