【问题标题】:How I can select a file with R, in this script如何在此脚本中使用 R 选择文件
【发布时间】:2022-10-21 20:24:30
【问题描述】:

嗨,这是我的脚本,我只想要名称为“胰腺”的文件。 如何在我的脚本中添加它?我有txt文件。

这是我的脚本:

  1. 生成文件夹中的文件列表:

    files <- data.frame(list.files(folder, recursive = TRUE, full.names = TRUE, pattern = '\\.txt$')[1:200])
    colnames(files)[1] <- "path"
    
  2. 删除文件名中包含“slide.txt”的记录:

    files <- subset(files, !grepl("slide.txt", files$path, fixed = TRUE))
    

    这是我的代码的屏幕截图:

【问题讨论】:

  • 不要发布代码截图.发布实际代码本身。

标签: r file select


【解决方案1】:
files <- list.files(".", pattern = "\.txt$", recursive = TRUE)
files
#> [1] "foo.txt"       "pancreas1.txt" "pancreas2.txt" "slide.txt"
pancreas_files <- grep(pattern = "pancreas", x = files, value = TRUE)
pancreas_files
#> [1] "pancreas1.txt" "pancreas2.txt"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多