How to separate data that is in the same column in Rstudio?

Asked

Viewed 34 times

0

Good evening, I have a table that I imported from excel to Rstudio and I want to work with the "Date" column. I need to separate the date from the hours and so far have not succeeded through the data.table, my goal is to create a column for "time" and a column for "date". Anyone who can help, thank you! tabela tem duas colunas

1 answer

1


Supposing that this separator between date and time is the space, you can do so:

Reproducible example:

df_1 <- data.frame(value = c("10", "20"), 
            Date = c("2021-10-01 03:15", "2021-10-01    00:20"))

Function:

library(dplyr)
library(tidyr)

df_1 %>% 
  separate(data = ., col = Date, 
       into = c("nova_data", "hora"), sep = "[[:space:]]+")

#   value  nova_data  hora
#1     10 2021-10-01 03:15
#2     20 2021-10-01 00:20

Browser other questions tagged

You are not signed in. Login or sign up in order to post.