[R-SIG-Finance] Read timeseries from csv file with xts or quantmod

Mark Breman breman.mark at gmail.com
Fri Jul 24 16:41:48 CEST 2009


Hi,
I have a timeseries in a csv file that I want to read into an xts object.

The csv file looks like:

1948-01-01 51,7
1948-02-01 50,2
1948-03-01 43,3
1948-04-01 45,4
1948-05-01 49,5
1948-06-01 53
1948-07-01 48,4
1948-08-01 45,1
1948-09-01 42,1
1948-10-01 47,2
1948-11-01 42,4
1948-12-01 35
1949-01-01 32,9
1949-02-01 31,3
1949-03-01 34,5
1949-04-01 35,5
1949-05-01 32,6
1949-06-01 31,6
etc...

I have attached it to this post.

I tried to read the file with getSymbols() but it gives me an error:
------------------------------------- start trace
----------------------------------------------
> library(quantmod)
> getSymbols('US_PMI_Monthly', src='csv', header = FALSE, sep = "\t",
dec=",")
Error in dimnames(x) <- dn :
  length of 'dimnames' [2] not equal to array extent
>
------------------------------------ end trace
-------------------------------------------------

Strange because read.csv() can read this file into a data.frame:

-------------------------------------- start trace
-----------------------------------------------
> data = read.csv("US_PMI_Monthly.csv", header = FALSE, sep = "\t", dec=",")
> class(data)
[1] "data.frame"
>
-------------------------------------- end trace
-------------------------------------------------

I tried to be smart and convert the data.frame to an xts object, but this
also gives me an error:

------------------------------------- start trace
-------------------------------------------------
> as.xts(data)
Error in as.POSIXlt.character(x, tz, ...) :
  character string is not in a standard unambiguous format
>
------------------------------------- end trace
---------------------------------------------------

I am using R 2.8.1 for windows with xts 0.6-6 and quantmod 0.3-10.

What am I doing wrong here?

Regards,

-Mark-
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20090724/c030bac0/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: US_PMI_Monthly.csv
Type: application/octet-stream
Size: 12407 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20090724/c030bac0/attachment.obj>


More information about the R-SIG-Finance mailing list