[R] stfrtime function not returning proper results through sqldf package in R

Manohar Reddy manu.reddy52 at gmail.com
Fri Sep 16 18:14:50 CEST 2016


First of all I would like to say thanks to everyone for sharing valuable
information, now I can able to do that if date column datatype is “Factor”
but by default the date column datatype is “POSIXct” in R ,so whenever I
want apply stfrtime function with sqldf package ,do I need to convert the
date datatype to factor ??? or is there any alternative  way?



Manu.

On Fri, Sep 16, 2016 at 9:08 PM, peter dalgaard <pdalgd at gmail.com> wrote:

>
> On 16 Sep 2016, at 15:23 , PIKAL Petr <petr.pikal at precheza.cz> wrote:
>
> > Hi Peter
> >
> > The devil is in detail
> >
> > Data from OP had different format and was transferred to Date object by
> as.Date, which results in incorrect values (and NA if not transferred)
> > df <- data.frame(Date = c("2013/05/25","2013/05/28","
> 2013/05/31","2013/06/01","2013/06/02",
> > "2013/06/05","2013/06/07"), Quantity = c(9,1,15,4,5,17,18))
> > df$Date<-as.Date(df$Date)
> > cbind(df, sqldf("select strftime( '%m', Date) from df"))
> >
>
> To be fair, he actually used as.Date(...., "%Y/%m/%d"), so the values were
> in fact correct. The issue lay in the conversion to integer.
>
> I can't figure out how those integers are interpreted, though:
>
> > df <- data.frame(date=c(0,1000,2000))
> > cbind(df, sqldf("select strftime( '%Y-%m-%d', date) from df"))
>   date strftime( '%Y-%m-%d', date)
> 1    0                  -471-11-24
> 2 1000                  -471-08-20
> 3 2000                  -470-05-16
>
> so the Epoch is nothing sensible and negative years are more than a
> thousand days??
>
>
> --
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Office: A 4.23
> Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com
>
>


-- 


Thanks,
Manohar Reddy P
+91-9705302062.

	[[alternative HTML version deleted]]



More information about the R-help mailing list