[R-SIG-Finance] Error in midnightStandard(charvec, format)

G See gsee000 at gmail.com
Wed Jun 6 02:45:08 CEST 2012


Hi Wei-han,

The problem is that your csv has tabs in the date.  One solution would
be to remove the tabs with gsub like this

    dataset$Date <- gsub("\t", "", dataset$Date)

That should get rid of the error.

A more elegant solution might be to use read.zoo from the zoo package
to read your csv.

HTH,
Garrett

On Tue, Jun 5, 2012 at 7:10 PM, Wei-han Liu <weihanliu2002 at yahoo.com> wrote:
> Hi R users:
>
> I am trying some functions in QRMlib package and applying to my own trial
> dataset but encountered the following error message when dealing with time
> series data.
>
> Error in midnightStandard(charvec, format) :
>   'charvec' has non-NA entries of different number of characters
>
>
> I have googled for some solution but the discussions are not clear enough to
> me if the issue can be solved or not. I suppose it is due to the data type
> conflict.
>
> Listed below is the coding and dataset is attached:
> dataset <- read.csv("D:/stockindex.csv", header=TRUE, sep = ",");
> tsData <- as.timeSeries(dataset);
> Date <- tsData[,1];
> SP500ts <- tsData[,2];
>
> SP500.nreturns <- -mk.returns(SP500ts);
> tD <- timeDate("05/16/1992","%m/%d/%Y");
> window <- (seriesPositions(SP500.nreturns) > tD);
> SP500.nreturns <- SP500.nreturns[window];
>
> Thanks for your attention and assistance.
>
> Wei-han
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.



More information about the R-SIG-Finance mailing list