I have a multiple text files, separated by a single space, that I need to
combine into a single data.frame.  Below is the track I'm on using
list.files to capture the names of the files and then lapply with
read.table.  But I run into problems making a usable dataframe out of the
data.


#Creating example data in similar format to data I have
sub <- rep(1,10)
trial <- seq(1,10,1)
size <- rep(3,10)
shortest <- rep(444,10)
startlab <- rep(444,10)
endlab <- rep(444,10)
startconf <- rep(444,10)
endconf <- rep(444,10)
steps <- sample(1:30,10)
time <- sample(1:300,10)

#creating example of text file and saving into a shared director with other
txt files

subject1 <-
cbind(sub1,trial,size,shortest,startlab,endlab,startconf,endconf,steps,time)
write.table(subject1, "C:Folder/R/subject1.txt", sep=" ")

#2nd example of same text file
sub <- rep(2,10)
trial <- seq(1,10,1)
size <- rep(3,10)
shortest <- rep(444,10)
startlab <- rep(444,10)
endlab <- rep(444,10)
startconf <- rep(444,10)
endconf <- rep(444,10)
steps <- sample(1:30,10)
time <- sample(1:300,10)

subject1 <-
cbind(sub1,trial,size,shortest,startlab,endlab,startconf,endconf,steps,time)
write.table(subject1, "C:Folder/R/subject2.txt", sep=" ")


setwd("C:Folder/R/")

#Getting list of file names
file_name <- list.files(pattern="subject*")

mydata <- lapply (file_name, read.table, sep=" ", header=T, row.names=NULL)



Thank you,
James

	[[alternative HTML version deleted]]

