Skip to content

Instantly share code, notes, and snippets.

@janeshdev
Last active August 24, 2016 20:23
Show Gist options
  • Save janeshdev/9283622 to your computer and use it in GitHub Desktop.
Save janeshdev/9283622 to your computer and use it in GitHub Desktop.

Revisions

  1. janeshdev revised this gist Mar 1, 2014. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion read_multiple_files.R
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    # Import files under folder name fawn
    # It is very important to include the option (full.names=TRUE). It it is not included then you will get the error something like
    # It is very important to include the option (full.names=TRUE). It it is not included
    # then you will get the error something like
    # "Error in file(file, "rt") : cannot open the connection In addition: Warning message:
    #In file(file, "rt") : cannot open file 'FAWN_2002.csv': No such file or directory

  2. janeshdev created this gist Mar 1, 2014.
    18 changes: 18 additions & 0 deletions read_multiple_files.R
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    # Import files under folder name fawn
    # It is very important to include the option (full.names=TRUE). It it is not included then you will get the error something like
    # "Error in file(file, "rt") : cannot open the connection In addition: Warning message:
    #In file(file, "rt") : cannot open file 'FAWN_2002.csv': No such file or directory

    mydata=ldply(list.files(path="data/fawn/",pattern="csv",full.names=TRUE),function(filename) {
    dum=read.csv(filename)
    dum$filename=filename
    return(dum)
    })

    # If you are already in the root folder and you want to read csv files, you can simply do:

    mydata=ldply(list.files(pattern="csv"),function(filename) {
    dum=read.csv(filename)
    dum$filename=filename
    return(dum)
    })