New to R, separating time and date into two columns

Hello,
I am very new to R. I am working on a capstone project, and I have separated the time and date into two columns, but when I view(), the columns are not separated. So here is the code I used.

all_trips %>%
separate(
started_at,
into = c("start_date", "start_time"),
sep = " ",
remove = FALSE
) %>%
mutate(
start_date = lubridate::as_date(start_date, format = "%Y-%m-%d"),
start_time = hms::as_hms(str_c(start_time, "00")))

dplyr doesn't perform "in-place" modifications, you have to explicitly assign the changes to a an object, if you want the output to overwrite the original data frame then use the assign operator <-

all_trips  <- all_trips %>%
separate(
started_at,
into = c("start_date", "start_time"),
sep = " ",
remove = FALSE
) %>%
mutate(
start_date = lubridate::as_date(start_date, format = "%Y-%m-%d"),
start_time = hms::as_hms(str_c(start_time, "00")))
1 Like

I just had an ah-ha moment. Thank you very much.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.