Tuesday, May 6, 2014

Transpose a matrix in R

Given a matrix or data.frame x, t returns the transpose of x.

> x <- matrix(1:20, ncol=4)
> x
     [,1] [,2] [,3] [,4]
[1,]    1    6   11   16
[2,]    2    7   12   17
[3,]    3    8   13   18
[4,]    4    9   14   19
[5,]    5   10   15   20
> t(x)
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    2    3    4    5
[2,]    6    7    8    9   10
[3,]   11   12   13   14   15
[4,]   16   17   18   19   20

3 comments:

  1. I will be happy if you read my comment. I must say that I like all your posts and wait for new ones. That's because they seem so great and suitable for me. Thanks a ton for uploading your articles.
    Short Ride game racing free || Jump Ball Blast Online games kids for school || online Downhill Rush

    ReplyDelete
  2. Do you know that there are readers loving to read your posts everyday? So please write and post more. I choose to follow your writing because they bring me what I want. They have knowledge and information. I will support you a lot. Thanks
    Wormana.io 2 player games || Christmas Gifts Mania new game || How to make frozen fever cake girls games for free

    ReplyDelete
  3. Christmas has come and New Year is coming. One of the things I will do next year is to follow your new posts. It's because they provide what I need. Your articles are informative and great. Stay healthy and write more posts. Thanks
    Short Ride || Kindergarten Dress Up games for kids for school || Moto X3M 2 free on abcya3 games

    ReplyDelete