file.names <- c("table1", "table2") #using fully
qualified names
table.list <- list()
i <- 0
for(table.name in table.names) {
i <- i+1
table.list[[i]] <- read.table(table.name)
}
Note the double sqare brackets. Use them also when accessing elements
to have them returned as data.frames (single brackets would return a
list of length 1 with the data frame being the only element)
On 3/12/06, Arnau Mir <arnau.mir at uib.es> wrote:> Hello.
>
> I have a lot of files that contain tables of data in a directory.
> I want to do the following in R but I don't know how:
>
> for i in 1 to the number of files
> {
> table[i]=read.table(file="file i")
> }
>
> The dimension of each table is different. All of these are tables of two
> dimensions.
>
> My first problem is to put all the file names in a table.
> Next, how I can load them using the command:
> read.table(file="file i") ?
>
>
> Thank in advance for your help,
>
> Arnau.
>
> ______________________________________________
> 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
>