0

I tried this code

fileList <- list.files(pattern=".csv")

df=sapply(fileList, read.csv)

View(df[[2]])

The 6 files name are 1521211800.csv

1521212400.csv

1521213000.csv

1521213600.csv

1521214200.csv

1521214800.csv

How can I import them and access each of them separately?

2 Answers2

1

Try this code:

Choose the folder containing your csv files:

path<-file.choose()

Save csv list files

fileList <- list.files(path=path,pattern=".csv")

Read all csv files

df=lapply(paste(path,fileList,sep="/"), read.csv)

Your output will have a list of dataframe corresponding to each csv loaded:

df
[[1]]
  a b c
1 1 1 1

[[2]]
  a b c
1 2 2 2
Terru_theTerror
  • 4,607
  • 2
  • 16
  • 33
0

first set your working directory, where all your files are stored there:

setwd("C:/Users/...") 

# then

file.List = list.files(pattern = "*.csv", recursive = F)

for (i in 1:length(file.List)) {

# open the files
input <- read.csv(file.List[i])

# assign a name 
assign(paste("df", (file.List[[i]])), input )

}
Hassan.JFRY
  • 805
  • 1
  • 5
  • 7