0

I want to convert multiple column containing date and timestamp as POSIXct. How to convert multiple columns with as.POSIXct function?

tgl1p tgl2bc
2021-12-10 09:54:00 2022-01-05 08:29:36
2021-05-19 15:37:43 2021-05-21 11:05:45
2021-12-13 16:44:01 2021-12-17 08:51:31

1 Answers1

3
library(tidyverse)

data <- tibble(tgl1 = "2021-12-10 10:00:32", tgl2 = "2021-12-13 14:59:14")

data %>%
  mutate(across(starts_with("tgl"), as.POSIXct))
#> # A tibble: 1 × 2
#>   tgl1                tgl2               
#>   <dttm>              <dttm>             
#> 1 2021-12-10 10:00:32 2021-12-13 14:59:14

Created on 2022-04-01 by the reprex package (v2.0.0)

danlooo
  • 10,067
  • 2
  • 8
  • 22