Last active
August 24, 2016 20:23
-
-
Save janeshdev/9283622 to your computer and use it in GitHub Desktop.
Read multiple csv files in R #csv #multiple #files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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