【发布时间】:2020-04-10 16:26:25
【问题描述】:
我怀疑这是一个小问题,但我想不通。 我有一个生成此列表数据的打包函数的输出:
output <- list(structure(c(69, 1.52224832314379, 5.1, 0.362256088534843,
46.9, -0.0364138250590129, 90.7, 3.0809104713466), .Dim = c(2L,
4L), .Dimnames = list(structure(c("N", "k"), .Dim = 1:2), c("Estimate",
"SE", "95% LCI", "95% UCI"))))
我想把它变成一个带有列 c("Parameter", "Estimate", "SE", "95% LCI", "95% UCI") 其中参数 = c("N", "k")
我已经尝试过 dplyr::unnest(output) no applicable method for 'unnest' applied to an object of class "list", unlist(output) 它返回 c(69, 1.52224832314379, 5.1, 0.362256088534843,
46.9, -0.0364138250590129, 90.7, 3.0809104713466) 但不保留任何名称。 purrr::flatten(output) 也不保留任何名称。
顺便说一句,我也不知道如何从列表中提取名称 - dimnames() 和 names() 返回 NULL。
【问题讨论】:
-
如果要转换成data.frame,就是data.frame(output[[1]]),但是听起来好像比较复杂?