[R] Help with changing date format in R

Sarah Goslee @@r@h@go@|ee @end|ng |rom gm@||@com
Wed Jan 20 19:47:40 CET 2021


Hi,

If the date format is determined by observer, you could for instance
use subset to divide it into two data frames, fix the dates and
recombine, or use ifelse to use the correct format based on observer.
This is a basic data manipulation task, and there are lots of ways
approach it.

Sarah

On Wed, Jan 20, 2021 at 1:32 PM 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.



-- 
Sarah Goslee (she/her)
http://www.numberwright.com



More information about the R-help mailing list