I have a data which is a m*n matrix. I would like to split the matrix by column and save each column separately in a different vector. E.g
data<-matrix(1:9, ncol=3)
I would like to have vec1
containing the first column so
vec1
will be transpose of[1,2,3]
, a column matrix with dimension 3*1 which is basically the first column of data. Similarly,vec2
represents the 2nd column andvec3
represents the last column.
I understand that I can do this manually by repeating
vec1<-data[,1],
vec2<-data[,2]
...
vecn<-data[,n].
However, this is not feasible when n is large. So I would like to know whether it is feasible to use a loop to do this.