f <- function (filename) { data<- read.csv(filename) .. } for (filename in paste0("data", 1:24, ".csv")) f(filename)
Depending on what exactly you have in your file system, for (filename in system("ls data*.csv", TRUE)) f(filename) might work. On Mon, 19 Feb 2024 at 16:33, Steven Yen <st...@ntu.edu.tw> wrote: > > I need to read csv files repeatedly, named data1.csv, data2.csv,… data24.csv, > 24 altogether. That is, > > data<-read.csv(“data1.csv”) > … > data<-read.csv(“data24.csv”) > … > > Is there a way to do this in a loop? Thank you. > > Steven from iPhone > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.