Hi Richard, This may be a bit ugly, but it should work if you have all your files in a folder you are calling from. Use dir() within the lapply call in combination with read.table as the function

require(plyr)

setwd("/Mac/R_stuff/files") # where your files are in this directory, and no files you don't need
data <- lapply(dir(), read.table, col.names=c("ID","count"), na.strings="-999.00") # -999 in case of missing values
data_new <- as.data.frame(matrix(nrow = length(data[[1]][,1]), ncol = length(names(data[[1]])))) # make empty data frame
for(i in 1:length(data)){ # loop removes each count column and adds it to data_new
data_new[,i] <- as.data.frame(data[[i]][,2])
}
data_new$ID <- data[[1]][,1] # add ID column to data_new

On Saturday, March 5, 2011 at 11:40 PM, Kingsley G. Morse Jr. wrote: 
> Hi Richard,
> 
> If you haven't tried it already, maybe you could
> read the files into separate data frames with
> read.table(), and then combine them with merge().
> 
> Type
> 
>  ?merge
> 
> to learn more.
> 
> Good luck,
> Kingsley
> 
> On 03/05/11 18:39, Richard Green wrote:
> > Hello R users,
> > I am fairly new to R and was hoping you could point me in the right
> > direction I have a set of text files (36).
> > Each file has only two columns (id and count) , I am trying to figure out a
> > way to load all the files together and
> > then have them ordered by id into a matrix data frame. For example
> > 
> > If each txt file has :
> > ID count
> > id_00002 20
> > id_00003 3
> > 
> > A Merged File:
> > ID count_file1 count_file2 count_file3 count_file4
> > id_00002 20 8 12 5 19 26
> > id_00003 3 0 2 0 0 0
> > id_00004 75 84 241 149 271 257
> > 
> > Is there a relatively simply way to do that in R? I was trying with <-
> > read.table
> > and then <- cbind but that does not appear to be working. Any suggestions
> > folks have are appreciated.
> > Thanks
> > -Rich
> > 
> >  [[alternative HTML version deleted]]
> > 
> > ______________________________________________
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> 
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

	[[alternative HTML version deleted]]

