0

I have 7 .csv files (each representing a location - Site1, Site2, Site3... Site7) in one folder and every .csv file contains 5 columns: ID, month, year, Species (with around 30 levels; different species), values(1, 2, 3, 4 - each of the number represents the intensity of flowering). I do not want to combine all the files together, as they contain different species and IDs, but instead I want to apply the same code that does a lot of cuts, interpolation and creates a named list of time series to all of them. At the end, the code gives a list of time series for each Species. At the moment I created a code that can be applied to only one site.

 data_list <- list() #create a list to fill in later 

for(sp in levels(Site1$Species)){
  dat.sp <- Site1[Site1$Species == sp,] # Distinguish between all Species 

  tree_list <- list()

  for (i in unique(dat.sp$ID)){

  other bit of code that cuts the data, 
  interpolates it and makes it as time 
  series. 


  data_list[[sp]]<-tree_list

How should I create the loop to run the same code to every Site ?

Gabriela
  • 11
  • 3
  • 1
    `lapply()` over the vector of filenames with a function which works for one file constructing the result. The result of the `lapply()` is a list of the results. – jogo Jan 21 '16 at 10:15
  • 1
    http://stackoverflow.com/questions/23853698/read-csv-as-list-from-multiple-folders?rq=1 or http://stackoverflow.com/questions/20425967/load-few-csv-files-from-the-same-folder?rq=1 – jogo Jan 21 '16 at 10:21
  • Possible duplicate of [Opening all files in a folder, and applying a function](http://stackoverflow.com/questions/9564489/opening-all-files-in-a-folder-and-applying-a-function) – scoa Jan 21 '16 at 15:03

1 Answers1

0

You don't need R for this.

Command line solution.

Make sure that no file contains a header
Open command line (cmd)
Enter correct directory (cd C:\yourdirectory)
Write (copy *.csv allcsvsmerged.csv)