Hi, I want to do automatic reading of a number of tables (files) stored in ascii format without having to specify the variable name in R each time. Below is an example of how I would like to use it (I assume files pair1,...,pair8 exist in spec. dire.) for (i in 1:8){ name <- paste("pair",i,sep="") ? ? ? <- read.table(paste("/home/andersm/tmp/",name,sep="")) } after which I want to have pair1,...,pair8 as tables. But I can not get it right. Anybody having a smart solution? Best regards, Anders Malmberg
for(i in 1:10){ assign( paste("data", i), i ) }> data1[1] 1> data5[1] 5> data8 + data5[1] 13 See help("assign") for more details and examples. On Wed, 2004-11-24 at 11:10, Anders Malmberg wrote:> Hi, > > I want to do automatic reading of a number of tables (files) stored in > ascii format > without having to specify the variable name in R each time. Below is an > example > of how I would like to use it (I assume files pair1,...,pair8 exist in > spec. dire.) > > for (i in 1:8){ > name <- paste("pair",i,sep="") > ? ? ? <- read.table(paste("/home/andersm/tmp/",name,sep="")) > } > > after which I want to have pair1,...,pair8 as tables. > > But I can not get it right. Anybody having a smart solution? > > Best regards, > Anders Malmberg > > ______________________________________________ > 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-- Adaikalavan Ramasamy ramasamy at cancer.org.uk Centre for Statistics in Medicine http://www.ihs.ox.ac.uk/csm/ Cancer Research UK Tel : 01865 226 677 Old Road Campus, Headington, Oxford Fax : 01865 226 962
Anders Malmberg wrote:> Hi, > > I want to do automatic reading of a number of tables (files) stored in > ascii format > without having to specify the variable name in R each time. Below is an > example > of how I would like to use it (I assume files pair1,...,pair8 exist in > spec. dire.) > > for (i in 1:8){ > name <- paste("pair",i,sep="") > ? ? ? <- read.table(paste("/home/andersm/tmp/",name,sep="")) > }pairlist <- vector(8, mode = "list") for (i in 1:8){ name <- paste("pair",i,sep="") pairlist[[i]] <- read.table(paste("/home/andersm/tmp/",name,sep="")) } or use assign(), but you don't want to do that really. Uwe Ligges> after which I want to have pair1,...,pair8 as tables. > > But I can not get it right. Anybody having a smart solution? > > Best regards, > Anders Malmberg > > ______________________________________________ > 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
Hi Andreas, what's about: pair <- list() for (i in 1:8){ name <- paste("pair",i,sep="") pair[[ i ]] <- read.table(paste("/home/andersm/tmp/",name,sep="")) } Arne On Wednesday 24 November 2004 12:10, Anders Malmberg wrote:> Hi, > > I want to do automatic reading of a number of tables (files) stored in > ascii format > without having to specify the variable name in R each time. Below is an > example > of how I would like to use it (I assume files pair1,...,pair8 exist in > spec. dire.) > > for (i in 1:8){ > name <- paste("pair",i,sep="") > ? ? ? <- read.table(paste("/home/andersm/tmp/",name,sep="")) > } > > after which I want to have pair1,...,pair8 as tables. > > But I can not get it right. Anybody having a smart solution? > > Best regards, > Anders Malmberg > > ______________________________________________ > 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-- Arne Henningsen Department of Agricultural Economics University of Kiel Olshausenstr. 40 D-24098 Kiel (Germany) Tel: +49-431-880 4445 Fax: +49-431-880 1397 ahenningsen at agric-econ.uni-kiel.de http://www.uni-kiel.de/agrarpol/ahenningsen/