Q:

How do I set the colnames of a matrix to the colnames of another matrix?

I have one data matrix named as.mat with dimensions [1] 79 1929 and another matrix, dd.mat with dimensions [1] 79 1924. dd.mat Has 1924 columns, but columns 1-1921 have no names.
For example, this is what it looks like when I do colnames(dd.mat):
[1] ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   "" [28] ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   ""   "" 
...up to the 1921th column. But columns 1922, 1923, and 1924 have the column name "nv":
[1918] ""   ""   ""   ""   "nv" "nv" "nv"
How would I set the colnames of as.mat to the first 1921 column names of matrix dd.mat without renaming the 1922nd to 1924th column?

A:

Just do the assignment combined with indexing
colnames(as.mat)[1:1921] <- colnames(dd.mat)[1:1921]

