简体   繁体   English

在 R 中将 yyyy-mm-dd hh:mm:ss 转换为 yyyymmddhhmmss

[英]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.

相关问题 R 数据格式:yyyy-mm-dd hh mm ss 到 yyyy-mm-dd - R data format : yyyy-mm-dd hh mm ss to yyyy-mm-dd 将 Julian 日数转换为日期时间格式 yyyy-mm-dd hh:mm:ss in R - convert Julian day number to date time format yyyy-mm-dd hh:mm:ss in R 需要将yyyy-mm-dd hh:mm:ss UTC转换为yyyy-mm-dd hh:mm格式 - Need to convert yyyy-mm-dd hh:mm:ss UTC to yyyy-mm-dd hh:mm format 在 R 中以 YYYY-mm-dd hh:mm:ss.0000000 格式转换日期时不适用 - NA when convert date in format YYYY-mm-dd hh:mm:ss.0000000 in R yyyymmddHHMMSS 转换为 yyyy-mm-ss HH:MM:SS - yyyymmddHHMMSS convert to yyyy-mm-ss HH:MM:SS 将R中的日期从yyyy-mm-dd转换为mm / dd / yyyy h:mm:ss - Convert date from yyyy-mm-dd to mm/dd/yyyy h:mm:ss in R 如何将格式为 dd-mm-yyyy hh:mm 的日期转换为 R 中的 yyyy-mm-dd - How to convert a date in the format dd-mm-yyyy hh:mm into yyyy-mm-dd in R 在R中将格式YYYY-MM-DD HH:MM:SS的列拆分为两列(日期对象)YYYY-MM-DD和HH:MM:SS - Split column of format YYYY-MM-DD HH:MM:SS to two (date object) columns YYYY-MM-DD and HH:MM:SS in R 从起源以来的分钟数转换为普通人的日期时间(“yyyy-mm-dd HH:MM:SS”)? - Convert from minutes since origin to date time for normal people (“yyyy-mm-dd HH:MM:SS”)? 通过在R中添加缺少时间的行来填写缺少的时间步长(yyyy-mm-dd HH:MM:SS) - Fill in missing time steps (yyyy-mm-dd HH:MM:SS) by adding rows with missing times in R
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM