I know this is a fairly basic topic, but it is one that caused me problems lately. Normally I only have to read in one data file at a time or I read in a few tables separately.
If I am reading in a single file would do the following
>read.table("file")
or if it is online
>read.table("url")
If it is a csv file
read.csv("file")
Now the problem arose because I needed to read in 400 files from a directory, but the files were not numerically indexed. So to solve this problem I used the functions list.files and paste.
>names<-list.files("~/directory/")
>complete_names<-paste( "~directory", names, sep="")
>for (i in sep_along(names){
monitors<-rbind(monitors, read.csv(complete_names[i]))
It was slow, but got the job done.
I blog about world of Data Science with Visualization, Big Data, Analytics, Sabermetrics, Predictive HealthCare, Quant Finance, and Marketing Analytics using the R language.
Showing posts with label reading lots of files into R. Show all posts
Showing posts with label reading lots of files into R. Show all posts
Sunday, June 8, 2014
Subscribe to:
Posts (Atom)