【发布时间】:2021-03-19 18:12:18
【问题描述】:
这样的列表模拟了我的一些数据,其中机器学习算法根据输入特征在预测响应变量中的重要性对它们进行排序:
feature <- rep(c("a", "b", "c", "d", "e", "f"), 3)
run <- c(rep(1, 6), rep(2, 6), rep(3, 6))
rank <- c(1, 2, 3, 4, 5, 6, 1, 4, 2, 3, 6, 5, 1, 5, 3, 4, 2, 6)
testlist <- list(feature, run, rank)
我想得到一个只包含排名数据的矩阵,格式如下:
[,1] [,2] [,3]
[1,] 1 1 1
[2,] 2 4 5
[3,] 3 2 3
[4,] 4 3 4
[5,] 5 6 2
[6,] 6 5 6
但是将批次转换为带有as.matrix() 的矩阵不会产生货物。我也尝试过dplyr::group_by() %>% dplyr::pull(),但我仍然无法将rank 与run 关联起来。
【问题讨论】:
-
matrix(testlist[[3]],ncol=3) -
@maydin 不错。还有:
matrix(testlist[[3]], ncol = length(testlist[[2]])/6)