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

R: how to assign columns to a matrix by column-name

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

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']

这样就可以了。

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