[R] Help with changing date format in R

Jeff Newmiller jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
Wed Jan 20 19:49:07 CET 2021


Perhaps

d$date <- as.Date(d$date, format = ifelse("K"==d$observer, "%d%m%Y", "%m%d%Y"  ))

On January 20, 2021 8:08:33 AM PST, krissievdh <krissievdh using gmail.com> wrote:
>Hi,
>
>I have a big database where one-third of the data is in a different
>date
>format than the rest. I'll add an example table to show you.
>
>| plot         | observer          | date            |
>| 1             | K                      | 31012020  |
>| 2             | K                      | 07022020  |
>| 3             | B                      | 01282020  |
>| 4             | B                      | 01292020  |
>So I have two different date formats; the first is in d m y while the
>other
>one is in m d y.
>
>My question is how can I change all the date data into the same format?
>Preferably in dd/mm/yy. (31-01-2020)
>I know I could use:
>d$date <- as.Date(d$date, format = "%d%m%Y")
>d$date <- as.Date(d$date, format = "%m%d%Y")
>
>but I can only do one and then it doesn't work. Is there a way i can
>use
>the first line for the date of observer K and the other line for the
>date
>of observer B?
>
>Thanks
>
>	[[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.

-- 
Sent from my phone. Please excuse my brevity.



More information about the R-help mailing list