[R] Dataset to single column matrix

arun smartpink111 at yahoo.com
Wed Jan 8 00:06:00 CET 2014


Hi,

You could try:
mat1 <- matrix(1:(272*12),ncol=12,byrow=TRUE)
 mat2 <- t(mat1)
 dim(mat2) <- c(272*12,1)


#or
mat3 <- matrix(as.vector(mat2),ncol=1)
identical(mat2,mat3)
#[1] TRUE


A.K.

Hello, 
I am pretty new to R and would like to transform my 272x12 matrix into a 3264X1. I'm trying to have the setup change from: 

1,  2,  3,  4, 5,  6, 7,  8, 9, 10, 11, 12 
13,14,15,16,17,18,19,20,21,22, 23, 24 
etc. 

to 

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
etc. 

Any suggestions? 
Thanks in advance



More information about the R-help mailing list