Rotate a Matrix in R

前端 未结 5 1129
情歌与酒
情歌与酒 2020-11-27 12:08

I have a matrix in R like this:

|1|2|3|
|1|2|3|
|1|2|3|

Is there an easy way to rotate the entire matrix by 90 degrees clockwise to get the

5条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 12:22

    Or combined in a single function (based on Eric Leschinski):

    rotate  <- function(x, clockwise=T) {
      if (clockwise) { t( apply(x, 2, rev))
      } else {apply( t(x),2, rev)} 
    }
    

提交回复
热议问题