I tried joining csv files present in two directories in R, having same name. For example 1.csv and 2.csv are present in /path/directory1 and /path/directory2. I joined the two files(1.csv with 1.csv). As given in below code:
directories <- c("/path/directory1", "/path/directory2")
files <- lapply(directories, list.files, pattern="*.csv", full.names = TRUE)
files <- lapply(files, sort)
joined <- Map(function(x,y) { join(read.csv(x), read.csv(y), by=c("date")) },
files[[1]], files[[2]])
Now, "joined" contains the list of csv’s. Now I want to store all the csv’s in directory (say “path/directory3”) but the csv name should be based on column For example, Every csv contains information about each country. There is “country” column: values are Australia, New Zealand, India, United States.
So, csv name should be Australia.csv, New Zealand.csv and so on.
Please help! Thanks in Advance!!