I have a folder of 100 CSV files. Each CSV file has same variables over same time period. My instructor has asked me to write a R script that will allow me to read each file to a separate Dataframe, and then call each Dataframe in R console, to get the summary statistics of the data. I have never attempted this outlandish task, I need help thanks.
Asked
Active
Viewed 338 times
0
-
5Welcome to StackOverflow. While I have found the `R` community on SO to be helpful and quick to respond, this is not a place where you can usually just ask others to do the work for you. You will get a better response if you show us what code you have already written and give us an example of your data. [This question](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) gives an excellent overview of how to ask a good `R`-related question that people will want to answer. See also this: [How to Ask](http://stackoverflow.com/questions/how-to-ask) – SlowLearner Jan 10 '13 at 08:37
-
1I agree with SlowLearner, SO is meant for specific questions. Read some manuals, some tutorials, and look around here on SO. There is more than enough material to get you started. See my answer below for some pointers. – Paul Hiemstra Jan 10 '13 at 08:45
-
1FWIW, http://stackoverflow.com/questions/9807945/consolidating-data-frames-in-r/9814834 http://stackoverflow.com/questions/10961512/merge-multiple-csv-files-and-remove-duplicates-in-r/10962422 – Roman Luštrik Jan 10 '13 at 09:00
1 Answers
2
Have no fear, at first each task in R seems outlandish without any experience. I can provide you with some pointers. In general it is a good idea to think first, and program later. This seems logical, but many people do not work this way. In this case for example a plan might look like:
- Get a list of the files in a directory. (
list.files
) - Loop over the list and read the files. (
lapply
orfor
,lapply
is more R-like) - Loop over the list of files and get the summary. (again
lapply
, andsummary
)
I provided some hints behind each step, you should read the documentation of these functions. In addition, I would first look at some basic R manuals, and look for some tutorials. This will give you a basis in R, which you can use to accomplish specific tasks. Good luck!

Paul Hiemstra
- 59,984
- 12
- 142
- 149
-
1+1 for giving general guidelines and not "being someone's mechanical turk". – Roman Luštrik Jan 10 '13 at 08:58