2015年8月19日 星期三

8.19 Reshape Matrix in R

http://www.sixhat.net/how-to-reshape-data-in-r.html

Basically, using the matrix() call specifying the dimension you want, and the output will be simply reshaped!

> a <- c(1, 2, 3, 4, 5, 6)
> matrix(a, 2, 3)
     [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6
> matrix(a)
     [,1]
[1,]    1
[2,]    2
[3,]    3
[4,]    4
[5,]    5
[6,]    6

沒有留言:

張貼留言