我的列表看起来像这样
Volumen(Ist) 800 200 300 200_2 200_3 82.0 100 .....
我需要这样的:
Volumen(Ist)
800
200
...
这里有一些关于我的代码的信息
> typeof(p1_daily)
[1] "list"
> p1_daily <- t(p1_daily)
[1] "logical"
> length(p1_daily)
[1] 0
> colnames(p1_daily)
NULL
> rownames(x)
[1] "Volumen (Ist)" "0" "69.000000000000028" "72" "76" "79" # .............. and so on
我不明白发生了什么。我只想将此列表作为包含一列的数据框。仅此而已。
谢谢!
编辑:
最佳答案
这样的东西会有帮助吗?
p1_daily <- list(`Volumen(Ist)` = cars[1:12,2])
p1_daily
#> $`Volumen(Ist)`
#> [1] 2 10 4 22 16 10 18 26 34 17 28 14
class(p1_daily)
#> [1] "list"
foo <- data.frame(`Volumen(Ist)` = unlist(p1_daily, use.names = FALSE) )
class(foo)
#> [1] "data.frame"
foo
#> Volumen.Ist.
#> 1 2
#> 2 10
#> 3 4
#> 4 22
#> 5 16
#> 6 10
#> 7 18
#> 8 26
#> 9 34
#> 10 17
#> 11 28
#> 12 14
如果您确实希望列名称为Volumen(Ist)
# install.packages(c("tidyverse"), dependencies = TRUE)
library(tibble)
bar <- tibble(`Volumen(Ist)` = unlist(p1_daily, use.names = FALSE))
bar
#> # A tibble: 12 x
#> `Volumen(Ist)`
#> <dbl>
#> 1 2
#> 2 10
#> 3 4
#> 4 22
#> 5 16
#> 6 10
#> 7 18
#> 8 26
#> 9 34
#> 10 17
#> 11 28
#> 12 14
关于R 列出数据框中的一列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48303154/