[R] Inputing data from multiple files as time series objects
Michaell Taylor
Michaell.Taylor at boxwoodmeans.com
Fri Nov 11 15:41:22 CET 2005
Assuming all the data are in a subdirectory called "Data" and all the files
have the '.txt' extension, you could do something like.
files <- list.files('Data')
for (file in files){
temp <- ts(read.table(file, header = T))
vname <- sub('.txt','',file)
assign(vname,temp,envir=.Globalenv)
}
On Friday 11 November 2005 08:07 am, Constantine Tsardounis wrote:
> Hello to everyone,...
>
> I am a new R ambitious user. I would like to be the first at my
> department using R, but I have encountered a difficulty during the
> last days that I cannot overcome reading help() and searching over the
> net.
> Problem:
> I have multiple files with financial data like the following (header
> included): E.g.:
> filename: AOL.txt
> aol.txt
> 4
> 3
> 5
> 3...
>
> filename: IBM.txt
> ibm.txt
> 6
> 2
> 5
> 2...
>
> I would like to input these data in R as time-series objects with
> their corresponding names automatically, so that I can manipulate them
> (exempli gratia plot acf, pacf, differntiate them, make adf tests,
> etc)
> For example: I could do that by hand using:
> AOL <- ts(read.table(AOL.txt, header = TRUE))))
> IBM <- ts(read.table(IBM.txt, header = TRUE))))
> but is there another way to achieve the same actions as above with a
> more versatile way? (for example loops?)
> Or would you suggest inputing these data with another way or as other
> objects?
>
> Thank you very much in advance,...
>
> Tsardounis Costas
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
--
=======================================
Michaell Taylor, PhD.
Principal
Boxwood Means, Inc.
203.653.4100
More information about the R-help
mailing list