我有一个名为as.mat
的数据矩阵,其维度为[1] 79 1929
,另一个矩阵dd.mat
的维度为[1] 79 1924
。 dd.mat
有1924列,但第1-1921列没有名称。
例如,这就是我colnames(dd.mat)
时的样子:
[1] "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" [28] "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
......直到1921年的专栏。但是列1922,1923和1924的列名为“nv”:
[1918] "" "" "" "" "nv" "nv" "nv"
如何在不重命名第1922行到第1924列的情况下,将as.mat
的列号设置为矩阵dd.mat
的前1921列名称?
答案 0 :(得分:2)
只需将作业与索引结合起来
colnames(as.mat)[1:1921] <- colnames(dd.mat)[1:1921]