[R] Date format

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Sun May 10 06:02:46 CEST 2020


True. Whence the error message then?

Still, in my attempt to reproduce, the format statement worked.

Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Sat, May 9, 2020 at 8:03 PM Jeff Newmiller <jdnewmil using dcn.davis.ca.us> wrote:
>
> ... but str says it is character. This must be 4.0...
>
> On May 9, 2020 7:17:16 PM PDT, Bert Gunter <bgunter.4567 using gmail.com> wrote:
> >$date is a factor, which is coded as numeric values internally, which
> >as.date sees as numeric, and therefore:
> >"as.Date will accept numeric data (the number of days since an epoch),
> >but only if origin is supplied." (from ?as.Date)
> >
> >You need to supply a format argument to as.Date to get it to handle
> >the factor properly; e.g.
> >"%d.%m.%Y"  should work. See ?strptime for formatting details.
> >
> >Bert Gunter
> >
> >"The trouble with having an open mind is that people keep coming along
> >and sticking things into it."
> >-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> >
> >On Sat, May 9, 2020 at 5:31 PM Medic <mailiPadpost using gmail.com> wrote:
> >>
> >> I took a SAMPLE CODE (for Connected scatterplot) from the R gallery
> >> and applied to MY DATA, but got:
> >> "Error in as.Date.numeric(mydata$date) : 'origin' must be supplied".
> >> P.S. I can not understand ?as.Date()
> >>
> >> SAMPLE CODE
> >> library(ggplot2)
> >> library(dplyr)
> >> library(hrbrthemes)
> >> data <-
> >read.table("https://raw.githubusercontent.com/holtzy/data_to_viz/master/Example_dataset/3_TwoNumOrdered.csv",
> >> header=T)
> >>
> >> str(data)
> >> 'data.frame': 1822 obs. of  2 variables:
> >>  $ date : chr  "2013-04-28" "2013-04-29" "2013-04-30" "2013-05-01"
> >...
> >>  $ value: num  136 147 147 140 126 ...
> >>
> >> data$date <- as.Date(data$date)
> >>
> >> # Plot
> >> data %>%
> >>   tail(10) %>%
> >>   ggplot( aes(x=date, y=value)) +
> >>     geom_line( color="grey") +
> >>     geom_point(shape=21, color="black", fill="#69b3a2", size=6) +
> >>     theme_ipsum() +
> >>     ggtitle("Evolution of bitcoin price")
> >>
> >>
> >> MY DATA
> >> mydata <- read.table("E:/mydata.csv", header=TRUE, sep=";", dec=",")
> >>
> >> str(mydata)
> >> 'data.frame': 7 obs. of  2 variables:
> >>  $ date : chr  "01.01.2000" "02.01.2000" "03.01.2000" "04.01.2000"
> >...
> >>  $ value: int  11 12 13 14 15 16 17
> >>
> >> mydata$date <- as.Date(mydata$date)
> >> Error in as.Date.numeric(mydata$date) : 'origin' must be supplied
> >>
> >> ______________________________________________
> >> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> 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 using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >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.
>
> --
> Sent from my phone. Please excuse my brevity.



More information about the R-help mailing list