To create a SQL query that will parse 3 files in a folder and add info to a database in R, we can follow the steps below:
DBI and odbc packages to do this.76 chars5 lineslist.files function in R. We can specify a pattern to match only the files we want to import.138 chars5 lines
read.csv function to read in each file as a data frame in R. We can then combine all the data frames using rbind and add a filename column to identify which file each row came from.114 chars3 linesdbWriteTable function in R to write the data to the database. We can also specify the table name and the database connection we established earlier.86 chars4 linesdbDisconnect function.19 chars2 linesPutting it all together, we have the following code:
436 chars18 linesThis code will parse 3 csv files in a folder and add their content to a table named my_table in a database, assuming you have already created the table and the database connection.
gistlibby LogSnag