2013-03-23 72 views
-1

如何加载由R中的文件夹组成的文件夹,适用于Windows?如何上传由R中的文件夹组成的文件夹,适用于Windows?我在每个文件夹中上传各种文本文件

我在每个子文件夹中都有各种文本文件,所有这些文件都是一次性加载的。 请建议一个方便简单的方法。

谢谢。

+0

您可以用'tar' – baptiste 2013-03-23 22:51:37

+1

“上传”是非常模糊的,你能澄清? – flodel 2013-03-23 23:10:23

+0

看起来像你需要'list.files(recursive = TRUE,..)'但我不确定,因为你不明确'上传'条款。 – agstudy 2013-03-23 23:19:13

回答

1

我假设通过“上传”您的意思是“加载到R”。有几种方法可以做到这一点,下面是两个。 注意,第一个步骤是有文件的完整路径正确的列表(或者在适当的wd合作)

# Get the list of files 
#----------------------------# 
    folder <- "path/to/files" 
    fileList <- dir(folder, recursive=TRUE) # grep through these, if you are not loading them all 

    # use platform appropriate separator 
    files <- paste(folder, fileList, sep=.Platform$file.sep) 


# Load them in 
#----------------------------# 
    # Method 1: 
    invisible(sapply(files, source, local=TRUE)) 

    #-- OR --# 

    # Method 2: 
    sapply(files, function(f) eval(parse(text=f))) 
+0

是的,我的意思是负载。你给的代码为我工作。谢谢! – 2013-03-25 15:12:03