[英]Convert yyyy-mm-dd hh:mm:ss to yyyymmddhhmmss in R
I have a data x
.我有一个数据x
。 It has a column time
.它有一个列time
。 This column has yyyy-mm-dd hh:mm:ss expression.此列具有 yyyy-mm-dd hh:mm:ss 表达式。
I want make this column has yyyymmddhhmmss expression.我想让这个专栏有 yyyymmddhhmmss 表达式。 For example, 2021-12-01 00:00:00
should be 20211201000000
.例如, 2021-12-01 00:00:00
应该是20211201000000
。 I use R programming.我使用 R 编程。 How can I do?我能怎么做?
We may use format
after converting to Datetime
class我们可以在转换为Datetime
class 后使用format
x$time <- format(as.POSIXct(x$time), "%Y%m%d%H%M%S")
Delete non-digits.删除非数字。
gsub('\\D', '', '2021-12-01 00:00:00')
# [1] "20211201000000"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.