[R-SIG-Finance] basic "date" issue

Samuel Le Samuel.Le at srlglobal.com
Fri Sep 24 17:22:59 CEST 2010


I think you should also set header=TRUE in read.table.

Samuel

-----Original Message-----
From: r-sig-finance-bounces at stat.math.ethz.ch [mailto:r-sig-finance-bounces at stat.math.ethz.ch] On Behalf Of Joshua Ulrich
Sent: 24 September 2010 14:34
To: Pam
Cc: r-sig-finance at stat.math.ethz.ch
Subject: Re: [R-SIG-Finance] basic "date" issue

Faith,

as.xts.data.frame assumes the rownames of the data.frame contain the
dates/times.  So you need to either:

1) Set the rownames before running as.xts:
rownames(Dataset) <- as.Date(Dataset[,1],"%d.%m.%Y")
as.xts(Dataset)

2) or, use the xts constructor:
xts(Dataset[,-1],as.Date(Dataset[,1],"%d.%m.%Y"))

HTH,
--
Joshua Ulrich
FOSS Trading: www.fosstrading.com



On Fri, Sep 24, 2010 at 8:20 AM, Pam <fkiraz11 at yahoo.com> wrote:
>
> Hi all,
>
> I think my problem is very basic but I could not manage to convert a dataframe
> (from clipboard for example) to xts object or at least convert the first
> variable of that frame as a date which is suitable for several financial
> packages we can use at R.
>
>> Dataset <- read.table("clipboard", header=FALSE, sep="", na.strings="NA",
> +   dec=",", strip.white=TRUE)
>
>> Dataset
>           V1             V2       V3            V4            V5
> V6          V7              V8
> 1 18.04.2006     00:00 54023.33 52627.51 54018.08 7.46  99.775.064   744.426.000
> 2 19.04.2006     00:00 55883.34 54018.08 55229.30 7.75 131.305.744 1.017.725.000
> 3 20.04.2006     00:00 55537.81 54762.96 55381.24 8.11  76.387.088   619.336.500
> 4 21.04.2006     00:00 57035.53 55207.06 57035.53 7.80 141.309.104 1.102.106.000
> 5 24.04.2006     00:00 57612.70 56493.95 57293.77 7.85 127.384.064   999.678.700
> 6 25.04.2006     00:00 57891.10 57151.94 57395.92 7.91 139.710.544 1.105.421.000
>
>> class(Dataset)
> [1] "data.frame"
>
>> as.xts(Dataset)
> Error in as.POSIXlt.character(x, tz, ...) :
>   character string is not in a standard unambiguous format
>
>> class(Dataset$V1)
> [1] "factor"
>
>> as.Date(Dataset$V1)
> Error in charToDate(x) :
>   character string is not in a standard unambiguous format
>
> I also tried the format tricks such as "%d-%m-%Y" or alike.. I will go crazy!!
> :)
>
> so, how can I turn this dataframe to "xts" and how can I convert V1 to a 'date'
> format recognized by the finance packages in R environment?
>
> Best,
> Fatih
>
>
>        [[alternative HTML version deleted]]
>
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch 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.
>

_______________________________________________
R-SIG-Finance at stat.math.ethz.ch 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.


__________ Information from ESET NOD32 Antivirus, version of virus signature database 5476 (20100924) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com



__________ Information from ESET NOD32 Antivirus, version of virus signature database 5476 (20100924) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com



More information about the R-SIG-Finance mailing list