Make sure to look at

as.character(FnO_Data$Date[m:l])

My $.02

/Henrik

On Sat, Sep 18, 2010 at 10:31 PM, Santosh Srinivas
<santosh.srini...@gmail.com> wrote:
> I tried this and it works too (For most part) .... strangely for certain
> dates (20090831) it is giving NA ...
>
>> FnO_Data$Date[m:l]
>  [1] 20090828 20090828 20090828 20090828 20090828 20090828 20090828 20090828
> 20090828 20090828 20090828 20090828
> [13] 20090828 20090828 20090828 20090828 20090828 20090828 20090828 20090828
> 20090828 20090828 20090828 20090828
> [25] 20090828 20090828 20090828 20090828 20090828 20090828 20090828 20090828
> 20090828 20090828 20090831 20090831
> [37] 20090831 20090831 20090831 20090831 20090831 20090831 20090831 20090831
> 20090831 20090831 20090831 20090831
> [49] 20090831 20090831 20090831
>> as.Date(as.character(FnO_Data$Date[m:l]), format="%Y%M%d")
>  [1] "2009-09-28" "2009-09-28" "2009-09-28" "2009-09-28" "2009-09-28"
> "2009-09-28" "2009-09-28" "2009-09-28"
>  [9] "2009-09-28" "2009-09-28" "2009-09-28" "2009-09-28" "2009-09-28"
> "2009-09-28" "2009-09-28" "2009-09-28"
> [17] "2009-09-28" "2009-09-28" "2009-09-28" "2009-09-28" "2009-09-28"
> "2009-09-28" "2009-09-28" "2009-09-28"
> [25] "2009-09-28" "2009-09-28" "2009-09-28" "2009-09-28" "2009-09-28"
> "2009-09-28" "2009-09-28" "2009-09-28"
> [33] "2009-09-28" "2009-09-28" NA           NA           NA           NA
> NA           NA
> [41] NA           NA           NA           NA           NA           NA
> NA           NA
> [49] NA           NA           NA
>> sessionInfo()
> R version 2.11.1 (2010-05-31)
> i386-pc-mingw32
>
> locale:
> [1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United
> Kingdom.1252
> [3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C
>
> [5] LC_TIME=English_United Kingdom.1252
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] zoo_1.6-4
>
> loaded via a namespace (and not attached):
> [1] grid_2.11.1    lattice_0.18-8 tools_2.11.1
>
>
> -----Original Message-----
> From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com]
> Sent: 18 September 2010 21:27
> To: Santosh Srinivas
> Cc: r-help@r-project.org
> Subject: Re: [R] Date issues
>
> On Sat, Sep 18, 2010 at 11:25 AM, Santosh Srinivas
> <santosh.srini...@gmail.com> wrote:
>> Strangely this is not working ... what am I doing wrong here?
>>
>>> tDate <- FnO_Data$Date[1]
>>> tDate
>> [1] 20090101
>>> as.Date(c(tDate),format="%Y%m%d")
>> [1] NA
>>
>
> Do you have zoo loaded?  If you do then a minimal reproducible example
> (see last line of every message to r-help) is:
>
>> library(zoo)
>> as.Date(20090101, format = "%Y%m%d")
> [1] NA
>
> Note that numeric arguments here are treated as the number of days
> since the Epoch and not as yyyymmdd.  As others have pointed out this
> works:
>
>> as.Date(as.character(20090101), format = "%Y%m%d")
> [1] "2009-01-01"
>
> --
> Statistics & Software Consulting
> GKX Group, GKX Associates Inc.
> tel: 1-877-GKX-GROUP
> email: ggrothendieck at gmail.com
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to