How to upload a folder consisting of folders in R, for windows? I am uploading various text files in each folder [closed]

笑着哭i 提交于 2019-12-13 10:22:59

问题


How to load a folder consisting of folders in R, for windows?

I have various text files in each sub-folder, all of which I want to load in one-go. Please suggest a convenient and easy method.

Thank you.


回答1:


I am assuming that by "upload" you mean "load into R". There are several ways to do this, below are two. Note that the first step is having the correct list of files with full path (or be working in the appropriate 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)))


来源:https://stackoverflow.com/questions/15593001/how-to-upload-a-folder-consisting-of-folders-in-r-for-windows-i-am-uploading-v

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!