Convert to Date in R - Character Strings to Date Format

preview_player
Показать описание
Most of the time when we load in CSV or Excel files, we expect that the variables will be the types we expect them to be. Number columns to be numbers, and dates to be dates.

But if we actually want to take advantage of all of the great functionality of the lubridate package that helps us work with dates in R, we need to use a different format.

While R will consider our date strings to just be a character, we can easily convert the column into a proper Date format that will behave more how we'd expect it to.

In this video, I show you a brief demonstration of the power of the lubridate package and how we can use a few handy functions to convert dates in almost any format into an actual, proper, date column.

At the end, I show you how we can put it all together in a clean chunk of code using dplyr and the piping functionality that comes with it. That will not only make our lives easier when coding it (no more pesky dollar signs to access variables), but will also make our code very readable if we need to come back to it months down the road.
Рекомендации по теме
Комментарии
Автор

Very trick and at time daunting working with dates in R. But you made it so simple and straitforward with the mdy(), ymd() and dmy() functions. Well done!

osoriomatucurane
Автор

Thank you for simplifying this function !

Marlorouse
Автор

Thank you so much, i was so frustrated

omolewaoreweme
Автор

Hi, thanks for this video, it's very helpful. If you don't mind me asking, what would you do in cases where the date and time are given together in a dataset? for example "Dec 04, 2021, 11:30:00AM" all in one column. I'm unsure of the best way to split them out and format them as dates/times. Thanks!

xoxojen
Автор

How do you retain the format of month-day-year?

Svykle
Автор

My dataset is different. The column names are the dates and not the cells below them. It doesn't seem to work.

briandong
Автор

is there a function for month/year or is it just for d/m/y?

lhamo
Автор

how to convert a number such as this into date ?

koushikvadali