0

Right now i am pulling out data from different CSV named test1_october, test2_october... from file October on my desktop. What my list does (I think) is compiles the name of all the tests (test1_october, test2_october, test3_october) and runs them on the function, and then binds all the data together.

compilation_file <- c("test1_october", "test2_october","test3_october")

list_compilation <- vector("list", length(compilation_file))

names(list_compilation) <- compilation_file

tests<- lapply(compilation_file, function(test_name) {

Reponses<-read.csv(paste("/Users/Desktop/October/response/",test_name,".csv", sep = ""))
.
.
.
 test_combined<-cbind()

  return(test_combined)
})

test_combined<-do.call(rbind,tests)

However, i want to try further this script to pull data from more than 1 file, so making the filename a variable in the function. For example, January, February... October, November, December

How do i add this second variable on the function and run this variable on another list, it will scan different folders and pull out the respective UNIQUE CSV.

compilation_file <- c("test1_october", "test2_october","test3_october","test4_november","test5_december")

compilation_folder <- c("january", "february", "october","november","december")

Thank you.

Werner Hertzog
  • 2,002
  • 3
  • 24
  • 36
Aloy
  • 1
  • 2
  • 1
    Welcome to StackOverflow! Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269). This will make it much easier for others to help you. – Sotos Oct 27 '17 at 10:13

1 Answers1

0

I'm not sure if this is what you want but i'll give it a try.

But if you try to give the filename as a parameter to your function you will just have to do something like this for your compilation_file :

    lfilename = toLower(filename)
    compilation_file_temp <- c("test1_"+lfilename, "test2_"+lfilename,"test3_"+lfilename)

    compilation_file <- c(compilation_file,compilation_file_temp)

This would be inside a loop that loops over the file names that you have inside a vector for example.

I'm not sure that this is what you want.

Zakaria Sahmane
  • 210
  • 2
  • 16
  • Hi Zakaria, thats a great addition but unfortunately my priority is open different folders according to the list and search for filename according to the list. For example,Open foldernames: January February,... December Look for individual file unique in each folder – Aloy Oct 27 '17 at 10:31
  • If you want to open multiple csv files check this : https://stackoverflow.com/questions/11433432/importing-multiple-csv-files-into-r – Zakaria Sahmane Oct 27 '17 at 10:58