[R] how to change format of dates in a tibble

Christopher W Ryan cry@n @end|ng |rom b|ngh@mton@edu
Wed Dec 18 17:45:44 CET 2019


I'm not understanding how the tidyverse handles date formats.

output of sessionInfo() at the end of my message.

dateRanges <- structure(list(apptType = structure(1:2, .Label = c("initial
visit",
"start of treatment visit"), class = "factor"), minMadeRequestDates =
structure(c(18124,
18115), class = "Date"), maxMadeRequestDates = structure(c(18187,
18199), class = "Date"), minApptDate = structure(c(18129, 18129
), class = "Date"), maxApptDate = structure(c(18199, 18214), class =
"Date")), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -2L))
str(dateRanges)

## produces desired result
format(dateRanges, format = "%d %b %Y")

## does not produce desired result
library(dplyr)
format(dateRanges, format = "%d %b %Y")

## rather cumbersome, and also does not produce the desired output
mutate(dateRanges, minMRD = as.Date(minMadeRequestDates, format = "%d %b
%Y"))

How does one change the format of a date variable inside a tibble when
dplyr is loaded?

Thanks

Chris Ryan

======== session info ===========
> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 7 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United
States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United
States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] dplyr_0.8.3

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.2       fansi_0.4.0      zeallot_0.1.0    utf8_1.1.4
crayon_1.3.4     assertthat_0.2.1 R6_2.4.0
 [8] backports_1.1.5  magrittr_1.5     pillar_1.4.2     rlang_0.4.0
 cli_1.1.0        vctrs_0.2.0      glue_1.3.1
[15] purrr_0.3.3      compiler_3.6.1   pkgconfig_2.0.3  tidyselect_0.2.5
tibble_2.1.3
====================================

	[[alternative HTML version deleted]]



More information about the R-help mailing list