Hi A simple question again, but I can't find it by google-ing R-help. Quite simply, I want to read in the contents of a number of files, using read.table, and assign the results to elements of a vector/array/list/whatever. I want it so that, if my vector/array/whatever is "pos", that pos[1] will give me the first data frame, pos[2] will give me the second etc... Kind of basic stuff I know... Sorry.. Mick
michael watson (IAH-C) wrote:> Hi > > A simple question again, but I can't find it by google-ing R-help. > > Quite simply, I want to read in the contents of a number of files, using > read.table, and assign the results to elements of a > vector/array/list/whatever. > > I want it so that, if my vector/array/whatever is "pos", that pos[1] > will give me the first data frame, pos[2] will give me the second etc...For sure you will find a solution! This has been answered several times. You can have a list "pos" (where pos is a bad time which suggest to have something in common with environments) so that pos[[1]] is your first data frame etc. See ?list Uwe Ligges> Kind of basic stuff I know... Sorry.. > > Mick > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
you could use something like: file. <- c:/data/dat # the path for the data lis.dat <- lapply(1:B, function(i) read.table(paste(file., i, sep="")) ) where B is the number of files whose names are: dat1, dat2, ..., datB. Then lis.dat[[1]] will be the first data.frame. I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/336899 Fax: +32/16/337015 Web: http://www.med.kuleuven.ac.be/biostat/ http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm ----- Original Message ----- From: "michael watson (IAH-C)" <michael.watson at bbsrc.ac.uk> To: <r-help at stat.math.ethz.ch> Sent: Thursday, February 17, 2005 2:01 PM Subject: [R] A vector or array of data frames> Hi > > A simple question again, but I can't find it by google-ing R-help. > > Quite simply, I want to read in the contents of a number of files, > using > read.table, and assign the results to elements of a > vector/array/list/whatever. > > I want it so that, if my vector/array/whatever is "pos", that pos[1] > will give me the first data frame, pos[2] will give me the second > etc... > > Kind of basic stuff I know... Sorry.. > > Mick > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >
"michael watson (IAH-C)" <michael.watson at bbsrc.ac.uk> writes:> Hi > > A simple question again, but I can't find it by google-ing R-help. > > Quite simply, I want to read in the contents of a number of files, using > read.table, and assign the results to elements of a > vector/array/list/whatever. > > I want it so that, if my vector/array/whatever is "pos", that pos[1] > will give me the first data frame, pos[2] will give me the second etc...No can do. pos[[1]] etc, however.... (pos[1] is another list, with one element, in this case the first data frame) x <- c("fee.dat","foe.dat","fie.dat","fum.dat") lapply(x, read.table, header=TRUE) # or whatever is needed> Kind of basic stuff I know... Sorry..-- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907