A <- matrix(1:16, 4)
# create an indicator for all diagonals in the matrix
d <- row(A) - col(A)
# use split to group on these values
split(A, d)
#
# $`-3`
# [1] 13
#
# $`-2`
# [1] 9 14
#
# $`-1`
# [1] 5 10 15
#
# $`0`
# [1] 1 6 11 16
#
# $`1`
# [1] 2 7 12
#
# $`2`
# [1] 3 8
#
# $`3`
# [1] 4
Related Contents:
- Function returns quadratic matrix in R [closed]
- Reshape three column data frame to matrix (“long” to “wide” format) [duplicate]
- Split a large dataframe into a list of data frames based on common value in column
- How to subset matrix to one column, maintain matrix data type, maintain row/column names?
- Creating co-occurrence matrix
- Sum rows in data.frame or matrix
- R memory management / cannot allocate vector of size n Mb
- Multiply rows of matrix by vector?
- All Levels of a Factor in a Model Matrix in R
- Index values from a matrix using row, col indices
- Subset a matrix according to a columns vector
- How can I create a correlation matrix in R?
- Extract matrix column values by matrix column name
- Last Observation Carried Forward In a data frame? [duplicate]
- R: Plotting a 3D surface from x, y, z
- How to divide each row of a matrix by elements of a vector in R
- Subscript out of bounds – general definition and solution?
- Apply a function to every row of a matrix or a data frame
- Rotate a Matrix in R by 90 degrees clockwise
- Create dataframe from a matrix
- Change row order in a matrix/dataframe
- Block-diagonal binding of matrices
- Directly creating dummy variable set in a sparse matrix in R
- R – How to get row & column subscripts of matched elements from a distance matrix
- Should I use a data.frame or a matrix?
- Find K nearest neighbors, starting from a distance matrix
- Select rows of a matrix that meet a condition
- Finding row index containing maximum value using R
- Function to split a matrix into sub-matrices in R
- How `poly()` generates orthogonal polynomials? How to understand the “coefs” returned?
- Loop in R: how to save the outputs?
- find neighbouring elements of a matrix in R
- R: How to rescale my matrix by column
- Get the row and column name of the minimum element of a matrix
- Split a vector into chunks
- grep using a character vector with multiple patterns
- How to find common elements from multiple vectors?
- Find the day of a week
- Scatterplot with marginal histograms in ggplot2
- Delete rows that exist in another data frame? [duplicate]
- ggplot2 – jitter and position dodge together
- dplyr: how to reference columns by column index rather than column name using mutate?
- How to calculate cumulative sum? [duplicate]
- How to use the strsplit function with a period
- Connecting across missing values with geom_line
- Generate random numbers with fixed mean and sd
- Create empty data frame with column names by assigning a string vector? [duplicate]
- How to make graphics with transparent background in R using ggplot2?
- R Scatter Plot: symbol color represents number of overlapping points
- How to label a barplot bar with positive and negative bars with ggplot2