x <- matrix(NA, nrow=5, ncol=4)
y <- t(x)
idxs <- seq(along=x)
# Assign by columns
x[idxs] <- idxs
print(x)
# Assign by rows
y[indexByRow(y, idxs)] <- idxs
print(y)
stopifnot(x == t(y))
Run the code above in your browser using DataLab