I have a large set of csv files in a single directory. These files contain two columns, Date
and Price
. The filename
of filename.csv
contains the unique identifier of the data series. I understand that missing values for merged data series can be handled when these times series data are zoo objects. I also understand that, in using the na.locf(merge() function
, I can fill in the missing values with the most recent observations.
I want to automate the process of.
- loading the
*.csv
file columnar Date and Price data into R dataframes. - establishing each distinct time series within the Merged zoo "portfolio of time series" objects with an identity that is equal to each of their s.
- merging these zoo objects time series using
MergedData <- na.locf(merge( ))
.
The ultimate goal, of course, is to use the fPortfolio
package.
I've used the following statement to create a data frame of Date,Price
pairs. The problem with this approach is that I lose the <filename>
identifier of the time series data from the files.
result <- lapply(files, function(x) x <- read.csv(x) )
I understand that I can write code to generate the R statements required to do all these steps instance by instance. I'm wondering if there is some approach that wouldn't require me to do that. It's hard for me to believe that others haven't wanted to perform this same task.