0

Currently having problem binding two sets of dataframes together.

Folder1 <-list.files(path[1],pattern=".csv")

Folder2 <-list.files(path[2],pattern=".csv")

File <-rbind(Folder1,Folder2)

Error:SQL logic error missing database near "AS":syntax error

Vinícius Félix
  • 8,448
  • 6
  • 16
  • 32
  • Firstly, you need to know what's the data class of `Folder1`. Obviously, it's not data frame. `list.files` only list the file name. It can't output the data frame. You need to read them with something like `fread` or `read.csv`. – Peace Wang Oct 07 '21 at 01:56
  • I have set Folder1<-data.frame(), then will Folder1<- list.files(path[1]) be a dataframe? – user17094143 Oct 07 '21 at 02:00
  • https://stackoverflow.com/questions/24819433/reading-multiple-csv-files-from-a-folder-into-a-single-dataframe-in-r – Peace Wang Oct 07 '21 at 02:03
  • What is `path` ? What is `length(path)` ? Are you trying to combine all the files in `path` together as one dataframe? – Ronak Shah Oct 07 '21 at 02:47
  • I am trying to combine all files name in certain folders into one big data frame such that I will have a big list of names of files. Only the name of the files and not the contents. – user17094143 Oct 07 '21 at 03:07

1 Answers1

0

You are not understanding exactly what list.files does. It creates a list of all the filenames that match your pattern and/or path. That does not mean however that anything has been imported yet.

This is the construction I usually use:

library(data.table) #for fread and rbindlist

Folder1_reads <- list()
Folder1_list <- list.files(path[1],pattern=".csv")
for (i in 1:length(Folder1_list)) {
  Folder1_reads[[i]] <- fread(paste(path[1], Folder1_list[i], sep = "/")) #maybe you won't need the "/" depending on what is in path[1]
}
Folder1 <- rbindlist(Folder1_reads)
koolmees
  • 2,725
  • 9
  • 23