Skip to content

Instantly share code, notes, and snippets.

@janeshdev
Last active August 24, 2016 20:23
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janeshdev/9283622 to your computer and use it in GitHub Desktop.
Save janeshdev/9283622 to your computer and use it in GitHub Desktop.
Read multiple csv files in R #csv #multiple #files
# 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)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment