I have a data x
. It has a column time
.
This column has yyyy-mm-dd hh:mm:ss expression.
I want make this column has yyyymmddhhmmss expression.
For example, 2021-12-01 00:00:00
should be 20211201000000
.
I use R programming. How can I do?
CodePudding user response:
We may use format
after converting to Datetime
class
x$time <- format(as.POSIXct(x$time), "%Y%m%d%H%M%S")
CodePudding user response:
Delete non-digits.
gsub('\\D', '', '2021-12-01 00:00:00')
# [1] "20211201000000"