R 读取多个文本文件函数

R 代码收集,一次性读取多个文本文件。

read.files <- function(folder, pattern) {
  ###
  # Read files
  #
  # @param folder: string
  # @param pattern: string
  # @return list
  # @example result <- read.files('./folder', '*.txt')
  ###
  filenames <- list.files(path=folder, pattern=pattern)
  filelist <- paste(folder, '/', filenames, sep='')
  all.lines <- lapply(filelist, FUN=readLines)
  
  lapply(all.lines, FUN=paste, collapse=' ')
}

作者: YanWen

Web 开发者

发表评论

Fill in your details below or click an icon to log in:

WordPress.com 徽标

You are commenting using your WordPress.com account. Log Out /  更改 )

Google photo

You are commenting using your Google account. Log Out /  更改 )

Twitter picture

You are commenting using your Twitter account. Log Out /  更改 )

Facebook photo

You are commenting using your Facebook account. Log Out /  更改 )

Connecting to %s