how to read multiple csv files from a directory in r
# Set the working directory to the path where your CSV files are located
setwd("path/to/your/directory")
# List all the CSV files in the directory
csv_files <- list.files(pattern = "\\.csv$")
# Create an empty list to store the data frames
list_of_dataframes <- list()
# Loop through each CSV file and read it into a data frame
for (file in csv_files) {
# Read the CSV file into a data frame
df <- read.csv(file)
# Add the data frame to the list
list_of_dataframes[[file]] <- df
}
# Access individual data frames from the list using file names
# For example, to access the data frame from a file named "example.csv"
# you can use list_of_dataframes[["example.csv"]]
Note: Replace "path/to/your/directory" with the actual path to the directory where your CSV files are located.