【问题标题】:Create text files with name of the files from a column in a data frame in R使用 R 中数据框中的列中的文件名创建文本文件
【发布时间】:2021-10-05 07:28:24
【问题描述】:

我在 R 中有一个数据框,其中包含我想在计算机文件夹中创建的文本文件(MSU870N.wea、MAU870N.tim 等)的名称。我如何在 R 中做到这一点。

【问题讨论】:

  • 你想在这些文件中放什么?您只是希望它们是空文本文件吗?
  • 您有文件名列表并且需要创建这些文件?奇怪,但是for (nm in filenameng$MSU870N) writeLines(character(0), nm)。这样,您将在当前目录中拥有 23 个空文件。
  • 这又快又简单:file.create(paste("path/to/directory/", filenameng$MSU870N, sep = ""))
  • 是的,我想要空文件,这很有效。感谢您的帮助。

标签: r file output


【解决方案1】:

像这样?

fn <- c("test1.txt", "test2.txt", "test3.txt")

for(name in fn)
  cat("This is a text file's content", file = name)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-07
    • 2022-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多