R:如何通过列名将列分配给矩阵

时间:2019-11-10 16:08:54

标签: r dataframe matrix columnsorting

我有一个形状正确的空矩阵(行和行)。我想一次将一列分配给该矩阵。

allf <- matrix(0, nrow = 2*h, ncol = ncol(ally))
colnames(allf)<- colnames(train)

Here, allf has columns from AA, AB.... AZ. 

Now, I want to assign the values by column name. As in:

allf.AA <- someothermatrix['xyz']

1 个答案:

答案 0 :(得分:0)

这可以做到。

allf[,'AA'] <- someothermatrix[,'xyz']