R How to Change the Data Class from Factor to Date (Example Code)
In this article you’ll learn how to switch data types from factor to Date in the R programming language.
Example Data
example_date <- factor("2021/07/15") # Date in factor format example_date # Print factor # [1] 2021/07/15 # Levels: 2021/07/15 |
example_date <- factor("2021/07/15") # Date in factor format example_date # Print factor # [1] 2021/07/15 # Levels: 2021/07/15
Example: Applying as.Date Function to Change Factor to Date Class
as.Date(example_date, format = "%Y/%m/%d") # Convert factor to Date # "2021-07-15" |
as.Date(example_date, format = "%Y/%m/%d") # Convert factor to Date # "2021-07-15"
Further Resources & Related Tutorials
In the following, you may find some additional resources that are similar to the content of this page.