【问题标题】:Exporting R lists value导出 R 列表值
【发布时间】:2019-05-13 18:13:38
【问题描述】:

我从 pdf 文件中提取了数据,现在我需要导出(excel、txt、任何东西)。它是列表格式的数据。

我试过了

capture.output(summary(text_lists), file = "My New File.txt")

但结果是

>Length Class  Mode     
> [1,] 60     -none- character

> [2,] 62     -none- character

> [3,] 60     -none- character

> [4,] 60     -none- character

然后我尝试了

>lapply(text_lists, function(x) write.table( data.frame(x), 'test.csv'  , >append= T))

>[[1]]
>NULL

>[[2]]
>NULL

>[[3]]
>NULL

如何提取列表的值以便能够导出?

【问题讨论】:

  • lapply(text_lists, function(x) write.table( data.frame(x), 'test.csv' , append= T)) 创建了一个 csv 文件,NULL 列表由write.table 函数是预期的

标签: r excel list export


【解决方案1】:

以下将 text_lists 转换为每个列表一列的数据框,然后输出一个 .csv 文件,每个列表将在其自己的列中。希望这有助于您实现目标。

maxlen <- max(sapply(text_lists, length))

res <- tibble::as_tibble(do.call(cbind,lapply(text_lists, `length<-`, maxlen)), .name_repair = "universal");

write.csv(res,"test.csv")

【讨论】:

    猜你喜欢
    • 2018-12-14
    • 1970-01-01
    • 1970-01-01
    • 2015-02-09
    • 2018-06-26
    • 1970-01-01
    • 2020-07-22
    • 2017-11-14
    • 1970-01-01
    相关资源
    最近更新 更多