0

I am importing a number of .CSV files using:

folder <- paste("D:/Folder/", sep = "")
file_list <- list.files(path=folder, pattern="*.csv")
for (i in 1:length(file_list)){assign(file_list[i], read.csv(paste(folder, file_list[i],sep=''), header = TRUE))}

The number of .CSV files may vary. So I need to Name those files from A to Z because I need to trim a few columns using

A =  select(A, Emp, Pro,Cust, Role) #using Dplyr package

and the merge those varying files using "merge"

The issue is: As those files will vary, using "Select" and "Merge" will not be possible which requires DataSet name.

zx8754
  • 52,746
  • 12
  • 114
  • 209
Adi.sr
  • 161
  • 1
  • 9

1 Answers1

0

You could use this to assign variables to letters in the global environment:

for (i in 1:length(file_list)){assign(letters[i], read.csv(paste(folder, file_list[i],sep=''), header = TRUE), .GlobalEnv)}

If you try to assign(file_list[i], ...) you are just basically replacing file_list with the data which doesn't seem to be what you want.

gaut
  • 5,771
  • 1
  • 14
  • 45