我有一个这样的数组:
> columnnames
[1] trade grain crude corn ship wheat acq interest money.fx earn
> summary(columnnames)
acq corn crude earn grain interest money.fx ship trade wheat
1 1 1 1 1 1 1 1 1 1
> str(columnnames)
Factor w/ 10 levels "acq","corn","crude",..: 9 5 3 2 8 10 1 6 7 4
并有另外一个这样的:
> rownames
[1] "tp" "fn" "fp" "tn" "tpr" "fnr" "precision" "recall" "acc" "Fmeasure"
问题很简单:如何使用这些行名和列名创建空矩阵或表(无关紧要)?
答案 0 :(得分:1)
您可以执行类似
的操作your.matrix <- matrix(NA, nrow = length(rownames), ncol = length(columnnames))
rownames(your.matrix) <- rownames
colnames(your.matrix) <- as.character(columnnames)
或
your.matrix <- matrix(NA, nrow = length(rownames), ncol = length(columnnames), dimnames = list(rownames, columnnames))