W3cubDocs

/Nushell

rotate for filters

Rotates a table or record clockwise (default) or counter-clockwise (use --ccw flag).

Signature

> rotate {flags} ...rest

Flags

  • --ccw, -: rotate counter clockwise

Parameters

  • ...rest: the names to give columns once rotated

Input/output types:

input output
record table
table table

Examples

Rotate a record clockwise, producing a table (like transpose but with column order reversed)

> {a:1, b:2} |rotate
╭───┬─────────┬─────────╮
# │ column0 │ column1 │
├───┼─────────┼─────────┤
01a
12b
╰───┴─────────┴─────────╯

Rotate 2x3 table clockwise

> [[ab]; [12] [34] [56]] |rotate
╭───┬─────────┬─────────┬─────────┬─────────╮
# │ column0 │ column1 │ column2 │ column3 │
├───┼─────────┼─────────┼─────────┼─────────┤
0531a
1642b
╰───┴─────────┴─────────┴─────────┴─────────╯

Rotate table clockwise and change columns names

> [[ab]; [12]] |rotatecol_acol_b
╭───┬───────┬───────╮
# │ col_a │ col_b │
├───┼───────┼───────┤
01a
12b
╰───┴───────┴───────╯

Rotate table counter clockwise

> [[ab]; [12]] |rotate--ccw
╭───┬─────────┬─────────╮
# │ column0 │ column1 │
├───┼─────────┼─────────┤
0b2
1a1
╰───┴─────────┴─────────╯

Rotate table counter-clockwise

> [[ab]; [12] [34] [56]] |rotate--ccw
╭───┬─────────┬─────────┬─────────┬─────────╮
# │ column0 │ column1 │ column2 │ column3 │
├───┼─────────┼─────────┼─────────┼─────────┤
0b246
1a135
╰───┴─────────┴─────────┴─────────┴─────────╯

Rotate table counter-clockwise and change columns names

> [[ab]; [12]] |rotate--ccwcol_acol_b
╭───┬───────┬───────╮
# │ col_a │ col_b │
├───┼───────┼───────┤
0b2
1a1
╰───┴───────┴───────╯

Tips: Command rotate was not included in the official binaries by default, you have to build it with --features=extra flag

Copyright © 2019–2023 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/rotate.html