Skip to content
Prev 179993 / 398506 Next

Read many .csv files into an R session automatically, without specifying filenames

On 12/05/2009, at 8:41 AM, Andreas Christoffersen wrote:

            
No; ``source'' is irrelevant here.
datalist <- list()
files <- list.files(pattern="\\.csv$")
	for(file in files) {
	stem <- gsub("\\.csv$","",file)
	datalist[[stem]] <- read.csv(file)
}

The foregoing does things the *right* way, putting the resulting data  
sets together
into a list whereby they can be accessed in an organized fashion.  If  
you wrong-headedly
*insist* on putting the data sets separately into your workspace then  
do:

files <- list.files(pattern="\\.csv$")
	for(file in files) {
	stem <- gsub("\\.csv$","",file)
	assign(stem,read.csv(file))
}

	cheers,

		Rolf Turner

######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}