【问题标题】:How to convert 900 text files, that contains 2 columns, into one data frame如何将包含 2 列的 900 个文本文件转换为一个数据框
【发布时间】:2020-10-20 15:03:54
【问题描述】:

我正在使用 R 并且我有 900 个看起来像这样的文本文件。它们包含两列,共 25 行。我需要将它们折叠到一个仅包含两列和 22,500 行的文件中。我真的不知道该怎么做。

desk          1
chair         0.98
sofa          0.90
room          0.88
dekstop       0.88
computer      0.83
book          0.50
room          0.45
cushion       0.30
pillow        0.25
bed           0.15
bedroom       0.14
window        0.10
curtain       0.11
yard          0.11
backyard      0.11
trees         0.11
grass         0.08
tomatoes      0.07
fruits        0.05
vegetables    0.05
vitamin       0.05
sun           0.02
moon          0.02
sky           0.02

【问题讨论】:

    标签: r merge text-files


    【解决方案1】:

    John Doe 的回答也适用于使用 cat *.txt > merged.txt

    的 MacOS(例如 How to open and use the Terminal app on a Mac computer

    您可能需要使用cd 命令“更改目录”到您的文件所在的位置。

    注意:各种 MacOS 使用不同的“shell”,请参阅 Apple 支持:

    通过更多搜索,R 中有 StackOverflow 解决方案,但 John Doe 在命令行终端中提出的命令更简单易用。

    Stack Overflow 中基于 R 的方法的一个示例:

    可以通过网络搜索找到更多...

    【讨论】:

      【解决方案2】:

      假设所有文件都在 1 个目录中。

      Windows command:type *.txt > merged.txt

      Linux command : cat *.txt > merged.txt

      使用 R,检查 this

      【讨论】:

      • 对不起,我想在哪里输入这个?
      • 添加了在 Windows 或 Linux 中打开终端的链接
      猜你喜欢
      • 2023-01-25
      • 1970-01-01
      • 2022-01-01
      • 1970-01-01
      • 2021-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多