Steven,

It depends what you want to do. What you are showing seems to replace the 
values stored in "data" each time.

Many kinds of loops will do that, with one simple way being to store all the 
filenames in a list and loop on the contents of the list as arguments to 
read.csv.

Since you show filenames as having a number from 1 to 24 in middle, you can 
make such a vector using paste().

A somewhat related question is if you want to concatenate all the data into one 
larger data.frame. 


-----Original Message-----
From: R-help <r-help-boun...@r-project.org> On Behalf Of Steven Yen
Sent: Sunday, February 18, 2024 10:28 PM
To: R-help Mailing List <r-help@r-project.org>
Subject: [R] Looping

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.

Reply via email to