read.multiple: Data Input from Multiple Files

read.multiple.tableR Documentation

Data Input from Multiple Files

Description

Open each of a set of files assumed to represent additional cases / observations on the same set of variables, then combine them into a single data frame containing all of the cases. For example, if data from 10 research participants are in 10 separate files, they can be read and combined into a single data frame.

Usage

read.multiple.table(
  uniquenames,
  path = getwd(),
  prefix = "",
  suffix = ".txt",
  addfilename = FALSE,
  paduniquenames = FALSE,
  ...
)

read.multiple.csv(
  uniquenames,
  path = getwd(),
  prefix = "",
  suffix = ".csv",
  addfilename = FALSE,
  paduniquenames = FALSE,
  ...
)

Arguments

uniquenames

A vector of string filenames, or if prefix and/or suffix are specified, a vector of the portion of the filename that uniquely identifies each filename.

path

Optional string indicating a path ("directory" or "folder") where to be appended to the start of every filename.

prefix

Optional string indicating a string that should be prepended to the start of each filename.

suffix

Optional string indicating a string that should be appended to the end of every filename.

addfilename

a logical value indicating whether a 'Filename' column should be added to the resulting dataframe indicating the filename of each original file.

paduniquenames

a logical value indicating whether each of the elements of uniquenames should be padded up to the length of the longest element by prepending zeros (e.g., '3' becomes '03').

...

arguments to read.table or read.csv.

Value

Data frame with the content of all of the files combined by rows.

See Also

read.table to read from a single file.

Examples

write.csv(data.frame(StudentName=c('Duane','Scott'), GPA=c(3.90, 2.3)),
          file='school01.csv', row.names=FALSE)
write.csv(data.frame(StudentName=c('Alison','Laurel'), GPA=c(2.90, 4.0)),
          file='school22.csv', row.names=FALSE)
allschools <- read.multiple.csv(uniquenames=c(1,22), prefix='school',
                                suffix='.csv',
                                paduniquenames=TRUE) # for 01 rather than 1

sfraundorf/psycholing documentation built on April 23, 2022, 2:50 a.m.