1

I am new to R and now I have an issue while I try to read CSV files in a loop. My CSV files are named as

result_file_1.csv , result_file_2.csv,....result_file_10.csv

So I planned to read a CSV by the below code:

for(i in 1:10){
t1=read.csv("result_file_i.csv")
// rest of my code
}

I also tried:

for(i in 1:10){
    t1=read.csv("result_file_"+i+".csv")
    // rest of my code
    }

both did not work. Any help is appreciated

Jaap
  • 81,064
  • 34
  • 182
  • 193
John
  • 305
  • 2
  • 4
  • 18
  • 3
    use `paste0()` to get the filename; `read.csv(paste0("result_file_", i , ".csv"))` – joel.wilson Dec 29 '16 at 11:07
  • 1
    @joel.wilson Works like a charm.Thanks a lot. – John Dec 29 '16 at 11:12
  • glad could help! however this was a poor question reflecting you didn't put much efforts to search online Sir. please do take it in a positive sense. Thank you! – joel.wilson Dec 29 '16 at 11:14
  • 1
    Possible duplicate of [Read multiple CSV files into separate data frames](http://stackoverflow.com/questions/5319839/read-multiple-csv-files-into-separate-data-frames) – PereG Dec 29 '16 at 11:18

1 Answers1

-2

As suggested above I used paste0("result_file",i,".csv") and it worked fine.

John
  • 305
  • 2
  • 4
  • 18