[R] macro in a loop

Le Wang ruser.le at gmail.com
Sat Mar 21 20:53:10 CET 2009

Hi there,

Thanks for your time in advance.

I am trying to read in multiple files. For example,

 data.1940 <- read.table("c:/data/1940.csv",header=TRUE,sep=",")	
 data.1950 <- read.table("c:/data/1950.csv",header=TRUE,sep=",")	
 data.1960 <- read.table("c:/data/1960.csv",header=TRUE,sep=",")	

How can I write a loop to read the data? I was trying to use the following


	for (j in 1:3){

	              data.year[j] <- read.table("c:/data/year[j]


But it is obviously wrong, as the marco is not proctected.

I have been googling around for a while but haven't succeeded in
finding any solutions. Thanks again for your help.


More information about the R-help mailing list