在R中转换非标准时间数据
我有一个包含非标准时间数据的数据集 - Excel 文件具有各种不同格式的数字,如下所示。
尝试将其转换为 R 中可用的内容 - 可能是 HH:MM AM/PM 所以我使用 mutate(H1B.format = format(strptime(H1B, "%I:%M %p"), "%H:%M"))。
我该怎么做 - 我尝试:separate(H1B, into = c('time', 'ampm'), sep = -2, conversion = TRUE) 将AM/PM放入单独的列中,但仍然需要计算了解如何根据需要添加冒号和零。
我对 R 也很陌生,所以任何帮助都会很棒!
I have a dataset with non-standard time data - the Excel file has numbers in a variety of different of different formats as shown below.
Trying to convert it to something usable in R - probably HH:MM AM/PM so I use mutate(H1B.format = format(strptime(H1B, "%I:%M %p"), "%H:%M")).
How would I do this - I tried: separate(H1B, into = c('time', 'ampm'), sep = -2, convert = TRUE) to put AM/PM into a separate column, but still need to figure out how to add colons and zeros as needed.
I'm also fairly new to R, so any help would be great!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 lubridate::parse_date_time 来解析各种格式的时间。
由 reprex 软件包 (v2.0.1) 创建于 2022 年 3 月 15 日
You can use
lubridate::parse_date_time
to parse times in various formats.Created on 2022-03-15 by the reprex package (v2.0.1)