【问题标题】:Split .txt format mixed table file in two table files将.txt格式的混合表文件拆分为两个表文件
【发布时间】:2021-01-17 12:25:49
【问题描述】:

在 R 编程语言中,是否可以像这样拆分 .txt 文件:mixed_data.txt ->

在两个 .txt 文件中,例如: file1.txt

和file2.txt

【问题讨论】:

    标签: r file split txt


    【解决方案1】:

    这是基于您的示例的尝试:

    # read in the original file
    x = readLines("example_mixed_dataset.txt")
    
    # break it into two pieces based on the first occurrence of the word "Index"
    # and write to two separate files
    index = grep("Index", x)
    writeLines(x[1:(index - 1)], "file1.txt")
    writeLines(x[index:length(x)], "file2.txt")
    

    此代码显然未经测试,因为我无法在您发布的文件图片上进行测试。如果有问题,请将示例数据以文本形式发布,不要以图片形式发布,否则无法调试。

    【讨论】:

      猜你喜欢
      • 2017-06-24
      • 1970-01-01
      • 1970-01-01
      • 2017-04-08
      • 2020-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-12
      相关资源
      最近更新 更多