# R, <s>121</s> 94 bytes <!-- language-all: lang-r --> function(A)t(outer(1:(n=NROW(A)),1:n,Vectorize(function(i,j)(-1)^(i+j)*det(A[-i,-j,drop=F])))) This is an absurdly long function that accepts an object of class `matrix` and returns another such object. To call it, assign it to a variable. Ungolfed: cofactor <- function(A) { # Get the number of rows (and columns, since A is guaranteed to # be square) of the input matrix A n <- NROW(A) # Define a function that accepts two indices i,j and returns the # i,j cofactor C <- function(i, j) { # Since R loves to drop things into lower dimensions whenever # possible, ensure that the minor obtained by column deletion # is still a matrix object by adding the drop = FALSE option a <- A[-i, -j, drop = FALSE] (-1)^(i+j) * det(a) } # Obtain the adjugate matrix by vectorizing the function C over # the indices of A adj <- outer(1:n, 1:n, Vectorize(C)) # Transpose to obtain the cofactor matrix t(adj) }