下面是一些虚拟数据和代码。我想我正在尝试与this question.完全相反
在操纵a statistical test后,我留下了一个非常丑陋的名单。当我解压缩此列表as per this method with unlist
时,存储在名称中的变量/国家/地区编码完全丢失。
我想有一个数据框与国家作为行名称和类别作为列名称。
任何指针将非常感谢!
set.seed(1)
CVtest <- list()
for (i in c("AT","BE","DE")) { #For all countries
# Test all categories together
CVtest[[i]][["EveryCat"]] <- sample(seq(0, 1, by=0.01), 1)
for (j in c("All", "Sub", "Key", "Sel")) { # Test each category
CVtest[[i]][[j]] <- sample(seq(0, 1, by=0.01), 1)
}
}
当前输出:
> class(CVtest)
[1] "list"
> CVtest
$`AT` EveryCat All Sub Key Sel
0.26 0.37 0.57 0.91 0.20
$BE EveryCat All Sub Key Sel
0.90 0.95 0.66 0.63 0.06
$DE EveryCat All Sub Key Sel
0.20 0.17 0.69 0.38 0.77
期望的输出
> class(CVtest)
[1] "data.frame"
> CVtest
EveryCat All Sub Key Sel
AT 0.26 0.37 0.57 0.91 0.20
BE 0.90 0.95 0.66 0.63 0.06
DE 0.20 0.17 0.69 0.38 0.77
你的问题仍然不明确(见我的最新评论)。我只能猜到你想要的东西。你能尝试一下:
x <- purrr::transpose(CVtest)
y <- rlist::list.stack(x)
rownames(y) <- names(x)
y
问我y
是否是所需的输出。否则我会删除这个答案,请澄清你的问题。