How about this for a more generalised matrix rotation function (works with 1-column and 1-row matrices too) ... rotate = function(mat) t(mat[nrow(mat):1,,drop=FALSE])
>>> From: <seeliger.c...@epamail.epa.gov> To:<r-help@r-project.org> Date: 19/Mar/2010 10:15a Subject: Re: [R] can I rotate a matrix > Now that *is* neat! Thanks! Unfortunately, it doesn't generalize and it's rather baroque. What is wanted is to make a matrix with row 1 as the last column, row 2 as the second to last column, etc. In otherwords, t(z[r:1,]) works for z <- matrix(c(1,2,1,3,2,6,4,5,3), ncol=3, byrow=TRUE) z <- matrix(c(1,2,1,3,2,6,4,5), ncol=4, byrow=TRUE) cur [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.