Re: [R] Reading multiple txt files into one data frame

From: Paul Lemmens <>
Date: Mon 31 Jul 2006 - 16:45:50 EST

On 7/30/06, Kartik Pappu <> wrote:
> Hello All,
> I have a device that spews out experimental data as a series of text
> files each of which contains one column with several rows of numeric
> data. My problem is that for each trial it gives me one text file
> (and I run between 30 to 50 trials at a time) and I would ideally like
> to merge all these text files into one large data frame with each
> column representing a single trial. It is not a problem if NA
> characters are added to make all the columna of eaqual length. Right
> now I am doing this by opening each file individually and cutting and
> pasting the data into an excel file. How can I do this in R assuming
> all my text files are in one directory.
> Is it also possible to customize the column headers. For example if I
> have 32 trials and 16 are experimental and 16 are control and I want
> to name the columns "Expt1", Expt2",... "Expt16" and the control
> columns "Cntl1",...Cntl16".
> Kartik
setwd("E:/Cooperation @ Delft-Nijmegen (Feb. 2006 - Sep. 2006)/Research/Study 20 - Roughness/Experiment 20a - Roughness Index for CUReT textures/Statistics")

# Concatenate the raw data files.
data.path = "../data files/"
(datafiles <- list.files(path=data.path, pattern="subject\_[0-9]+\.txt$")) exp20a <-'rbind',
    function(x) read.table(paste(data.path, x, sep="")))) rm(datafiles, data.path) mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Mon Jul 31 17:54:27 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Mon 31 Jul 2006 - 18:22:37 EST.

Mailing list information is available at Please read the posting guide before posting to the list.