If all entries in dt1
are of the same type (either numbers or strings or TRUE
/FALSE
), then this will be easier and faster to do with reindexing/reshaping matrices:
dt1 <- matrix(11:34, ncol=4, byrow=TRUE)
dt1
# [,1] [,2] [,3] [,4]
#[1,] 11 12 13 14
#[2,] 15 16 17 18
#[3,] 19 20 21 22
#[4,] 23 24 25 26
#[5,] 27 28 29 30
#[6,] 31 32 33 34
dt2 <- matrix(as.vector(t(dt1)), ncol=12, byrow=TRUE)
dt2
# [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
#[1,] 11 12 13 14 15 16 17 18 19 20 21 22
#[2,] 23 24 25 26 27 28 29 30 31 32 33 34