2014-09-02 136 views
-1

我有一個數據矩陣as.mat尺寸[1] 79 1929和另一個矩陣dd.mat尺寸[1] 79 1924dd.mat有1924列,但1-1921列沒有名字。 例如,這是個什麼樣子,當我做colnames(dd.mat),如:如何將矩陣的名稱設置爲另一個矩陣的名稱?

[1] "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" [28] "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

...到1921th列。但是,列1922年,1923年和1924年有列名「NV」:

[1918] "" "" "" "" "nv" "nv" "nv"

我將如何設置的as.mat以矩陣dd.mat的第一1921年列名colnames不重新命名第一千九百二十二到1924th列?

回答

2

只是做了分配與索引結合

colnames(as.mat)[1:1921] <- colnames(dd.mat)[1:1921]