0
votes

I've imported a dataset with dates in the format 'month year' (e.g. July 2020), which have automatically been parsed as characters. I'm trying to convert them to dates, using lubridate::parse_date_time(). When I do this, lubridate returns a list of dates (e.g. "2020-07-01 UTC", "2020-07-01 UTC", "2020-07-01 UTC", "2020-07-01 UTC", "2020-07-01 UTC", "2020-06-01 UTC", "2020-06-01 UTC", "2020-06-01 UTC", "2020-06-01 UTC", "2020-06-01 UTC" etc).

This is what I want, but now I'm stuck: I'm not sure how to get these back into my original dataframe, replacing the previous column of characters with this new date representation. Is there a really obvious way to do this?

1
Hi bee, welcome to Stack Overflow. It will be much easier to help if you provide at least a sample of your data with dput(data) or if your data is very large dput(data[1:20,]). You should replace data with the name of your actual data.frame. You can edit your question and paste the output. Please surround the output with three backticks (```) for better formatting. See How to make a reproducible example for more info.Ian Campbell
Does this answer your question? Adding a column to a data.frameIan Campbell
@IanCampbell Along with the below answer this cleared up the problem! I will make sure to provide a sample of my data next time I ask a question. Thank you for your help.bee

1 Answers

0
votes

Try

dataframe %>% mutate(date = parse_date_time(date)) -> dataframe

or

dataframe$date <- parse_date_time(dataframe$date)