Dear Yao, You can use a list() as follows (untested):
setwd("~/path/to/your/files") f <- list.files(pattern = ".txt") # list the files info <- lapply(f, read.table, header = TRUE) names(info) <- f info To see the information in the first data set just do info[[1]] See ?list.files and ?lapply for more information. HTH, Jorge On Thu, Dec 20, 2012 at 3:24 PM, Yao He <> wrote: > Dear All > > I have a lot of files in a directory as follows: > "02-03.txt" "03-04.txt" "04-05.txt" "05-06.txt" "06-07.txt" > "07-08.txt" "08-09.txt" > "09-10.txt" "G0.txt" "G1.txt" "raw_ped.txt" > .......................... > > I want to read them into different objects according to their > filenames,such as: > 02-03<-read.table("02-03.txt",header=T) > 03-04<-read.table("03-04.txt",header=T) > I don't want to type hundreds of read.table(),so how I read it in one time? > I think the core problem is that I can't create different objects' > name in the use of loop or sapply() ,but there may be a better way to > do what I want. > > Thanks a lot > > Yao He > > Yao He > > > -- > > Master candidate in 2rd year > Department of Animal genetics & breeding > Room 436,College of Animial Science&Technology, > China Agriculture University,Beijing,100193 > E-mail: yao.h.1...@gmail.com > > > ______________________________________________ > 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]]
______________________________________________ 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.