Skip to content
Prev 295666 / 398502 Next

Reading a bunch of csv files into R

For example:

myDir <- "some file path" 
filenames <- list.files(myDir)
filenames <- filenames[grep("[.]csv", filenames)]

data_names <- gsub("[.]csv", "", filenames)

for(i in 1:length(filenames)) assign(data_names[i], read.csv(file.path(myDir, filenames[i])))

?

 Benjamin Nutter |??Biostatistician   ? |??Quantitative Health Sciences
? Cleveland Clinic?   | ?9500 Euclid Ave.? | ?Cleveland, OH 44195? |?(216) 445-1365


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Kevin Wright
Sent: Friday, May 25, 2012 2:55 PM
To: HJ YAN
Cc: r-help at r-project.org
Subject: Re: [R] Reading a bunch of csv files into R

See ?dir

Assign the value to a vector and loop over the elements of the vector.

Kevin
On Fri, May 25, 2012 at 12:16 PM, HJ YAN <yhj204 at googlemail.com> wrote:
--
Kevin Wright

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


===================================

 Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News & World Report (2010).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}