Skip to content

Instantly share code, notes, and snippets.

@jonesor
Last active July 18, 2026 20:19
Show Gist options
  • Select an option

  • Save jonesor/1cb7178db13ee4f002d5 to your computer and use it in GitHub Desktop.

Select an option

Save jonesor/1cb7178db13ee4f002d5 to your computer and use it in GitHub Desktop.
Rotate a matrix through 90 degrees clockwise
# Rotate a matrix through 90 degrees clockwise.
# drop = FALSE keeps the result a matrix even when m has a single row.
m <- t(m[nrow(m):1, , drop = FALSE])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment