I have a directory and in my directory there are multiple files. Each file having different csv. For example in my directory there is 5 files (in actual case more than 100), and each file having 10 .csv file.
My question is that I want to select different columns (all files having equal no of columns) from that files and merge them and create a single data frame.
My data frame looks like -
Main Directory -
File1-
a.csv -
store_code Tran1 Tran2 Tran3
10 5454 7645 7111
10 4154 7675 7000
10 1454 2145 8431
.........
b.csv -
store_code Tran1 Tran2 Tran3
10 5004 6645 7291
10 4109 1675 7000
10 9454 1045 1031
.........
File2-
c.csv -
store_code Tran1 Tran2 Tran3
20 1054 2045 1111
20 2954 3075 7080
20 1454 2145 8431
.........
d.csv -
store_code Tran1 Tran2 Tran3
20 1994 2045 9011
20 2004 3075 8080
20 1004 2145 1031
.........
I have done the merging of all files from a directory. But unable do select multiple column and then merge. For this example suppose I want to select two columns store_code and Tran2 and then merge all them.
For merging purpose I have done the following code -
i.Main directory set as a working directory where all files are there.
ii.csv_files <- dir(pattern='.*[.]csv', recursive = T)
library(dplyr)
df <- rbind_all(lapply(csv_files, read.csv))
My expected output -
store_code Tran3
10 7111
10 7000
10 1111
.. ----
20 9011
20 8080