[R] How do I "teach" R that columns 1, 2, and 3 are the Year-Month-Day

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Wed Jun 15 20:07:34 CEST 2022


Look again -- perhaps in your spam folder.

Here's what he said:

"
Reprex:

dta <- read.table( text =
"Yr  Mo Dy   Fuel
2021  7 25   50.45
2021  8 27   61.48
2021  9 26   59.07
2021 11  4   55.40
2021 11 22   30.63
2021 11 26   41.35
2021 12  6   32.81
2022  1 14   49.86
2022  4 29   62.99
2022  6 11   89.37
", header=TRUE )
dta$Dtm <- with( dta, as.Date( ISOdate( Yr, Mo, Dy ) ) )
with( dta, plot( Dtm, Fuel ) )

The ISOdate function returns a POSIXct which includes time-of-day.
Analyses that don't need time can instead rely on the Date type to
avoid issues with timezones. "


Bert Gunter

On Wed, Jun 15, 2022 at 9:58 AM Gregory Coats via R-help
<r-help using r-project.org> wrote:
>
> I do not see any posting on this topic from Jeff Newmiller.
> I seek a way to “teach” R that "2021-07-25” represents a Year, Month, and Day.
> Greg Coats
>
> > Fuel <- c(50.45, 61.48, 59.07, 55.40, 30.63, 41.35, 32.81, 49.86, 62.99, 89.37)
> > plot (Fuel)
> > Dates <- c("2021-07-25", "2021-08-27", "2021-09-26", "2021-11-04", "2021-11-22", "2021-11-26", "2021-12-06", "2022-01-14", "2022-04-29", "2022-06-11")
> > plot (Dates)
> Error in plot.window(...) : need finite 'ylim' values
> In addition: Warning messages:
> 1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
> 2: In min(x) : no non-missing arguments to min; returning Inf
> 3: In max(x) : no non-missing arguments to max; returning -Inf
>
> > xyplot (Dates, Fuel)
> Error in xyplot(Dates, Fuel) : could not find function "xyplot"
>
> > On Jun 15, 2022, at 6:02 AM, Martin Maechler <maechler using stat.math.ethz.ch> wrote:
> > Jeff Newmiller's answer which was much shorter *and* only
> > used base R  instead of an extra package
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.



More information about the R-help mailing list