Say one is trying to paste two matrices together, both of which have been given column labels using a list() with colnames(). Using cbind() in R works as expected for the data, but the column labels seem to get lost after the cbind() operation (the column labels become V1, V2, etc...). This would be part of a function and each matrix would be an input to the function so one or both of the matrices being appended would usually contain a different number of columns (but always the same number of rows).
Is there a way to retain the column names when binding the two matrices using cbind(), or is there an alternative way to append one matrix to the other that will retain the column labels?
Thanks in advance!
m1<-matrix(1:8, nrow=2, dimnames=list(NULL, letters[1:4])); m2<-matrix(1:6, nrow=2, dimnames=list(NULL, letters[5:7])); cbind(m1,m2)
. Can you provide a reproducible example of a case where it doesn't work? – MrFlickvectorlist
? Probably should bevectorlist[[1]]
. But you should edit your question with a reproducible example as already requested (rather than posting in comments) – MrFlick