In my package HelpersMG, I have included a function to read in one time
all the files of a folder and they are stored in a list:
read_folder(
folder = try(file.choose(), silent = TRUE),
file = NULL,
wildcard = "*.*",
read = read.delim,
...
)
In your case, for example:
library("HelpersMG")
data_list <- read_folder(folder=".", file=paste0("data",
as.character(1:24),".csv"), read=read.csv)
data_df <- do.call("rbind", data_list)
Marc
Le 19/02/2024 à 04:27, Steven Yen a écrit :
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.