# Reference/cut

From Kx Wiki

(Difference between revisions)

(Fixed errors and added additional usage) |
Chris Burke (Talk | contribs) |
||

Line 1: | Line 1: | ||

− | + | {{refheader|cut|cut verb}} | |

− | + | Verb <tt>cut</tt> splits its right argument according to its left. | |

+ | |||

+ | == Syntax == | ||

<pre> | <pre> | ||

Line 7: | Line 9: | ||

</pre> | </pre> | ||

− | + | <tt>cut</tt> has two slightly different behaviors, depending on its left argument: | |

− | + | ||

+ | *if <tt>X</tt> is a single integer, <tt>cut</tt> splits its right argument into <tt>X</tt>-sized parts, for example: | ||

<pre> | <pre> | ||

− | + | q)4 cut til 10 | |

+ | 0 1 2 3 | ||

+ | 4 5 6 7 | ||

+ | 8 9 | ||

</pre> | </pre> | ||

− | + | *if <tt>X</tt> is a non-decreasing list of integers, it cuts <tt>Y</tt> at the indices given in <tt>X</tt>. The result R has the same number of elements as X and will always be a list. For example: | |

<pre> | <pre> | ||

− | q) | + | q)2 4 9 cut til 10 / the first result item starts at index 2 |

− | q) | + | 2 3 |

− | + | 4 5 6 7 8 | |

+ | ,9 | ||

+ | q) | ||

+ | q)2 4 4 9 cut til 10 / cuts are empty for duplicate indices | ||

+ | 2 3 | ||

+ | `int$() | ||

+ | 4 5 6 7 8 | ||

+ | ,9 | ||

</pre> | </pre> | ||

− | + | == Remark == | |

− | + | <tt>cut</tt> is a simple derivative of the primitive <tt>_</tt> (drop/cut). Where the left argument is an atom, it cuts the right argument into equal sized parts, and otherwise it behaves like <tt>_</tt>. For example: | |

<pre> | <pre> | ||

− | q) | + | q)"abcde" _ 3 / drop element with index 3 |

− | + | "abce" | |

− | + | q)"abcde" cut 3 / cut works the same | |

− | q) | + | "abce" |

− | + | ||

</pre> | </pre> | ||

− | + | == See also == | |

− | + | *[[Reference/Underscore|drop/cut]] | |

− | + | ||

− | + | ||

− | + | ||

− | + | ||

− | + | ||

− | + | ||

---- | ---- | ||

For a complete list of functions, see the [[Reference|kdb+ Function Reference]]. | For a complete list of functions, see the [[Reference|kdb+ Function Reference]]. |

## Latest revision as of 09:51, 12 October 2009

## Contents |

## cut (cut verb)

Verb `cut` splits its right argument according to its left.

## Syntax

R:X cut Y

`cut` has two slightly different behaviors, depending on its left argument:

- if
`X`is a single integer,`cut`splits its right argument into`X`-sized parts, for example:

q)4 cut til 10 0 1 2 3 4 5 6 7 8 9

- if
`X`is a non-decreasing list of integers, it cuts`Y`at the indices given in`X`. The result R has the same number of elements as X and will always be a list. For example:

q)2 4 9 cut til 10 / the first result item starts at index 2 2 3 4 5 6 7 8 ,9 q) q)2 4 4 9 cut til 10 / cuts are empty for duplicate indices 2 3 `int$() 4 5 6 7 8 ,9

## Remark

`cut` is a simple derivative of the primitive `_` (drop/cut). Where the left argument is an atom, it cuts the right argument into equal sized parts, and otherwise it behaves like `_`. For example:

q)"abcde" _ 3 / drop element with index 3 "abce" q)"abcde" cut 3 / cut works the same "abce"

## See also

For a complete list of functions, see the kdb+ Function Reference.