我需要将日期时间拆分成两列。

huangapple go评论72阅读模式
英文:

I need to split date time into two columns

问题

I tried a couple of codes but failed. 我尝试了几段代码但失败了。

I checked the youtube to understand it but did not succeed. 我查看了YouTube以了解,但没有成功。

The youtube link https://www.youtube.com/watch?v=Phib0IUNdg8 YouTube链接 https://www.youtube.com/watch?v=Phib0IUNdg8

I looked into R for the data science book under the Dates and Time page. 我查阅了数据科学书中关于日期和时间的部分。

I have used as. date() function it didn't work. 我使用了 as.date() 函数,但它没有起作用。

I tried to separate () too but no result. 我也尝试了分开 (),但没有结果。

I am missing a concept please let me know. 我缺少一个概念,请告诉我。

Please help me. 请帮助我。

英文:

I tried a couple of codes but failed. I checked the youtube to understand it but did not succeed. The youtube link https://www.youtube.com/watch?v=Phib0IUNdg8

I looked into R for the data science book under the Dates and Time page. I have used as. date() function it didn't work. I tried to separate () too but no result. I am missing a concept please let me know.

Please help me.enter image description here

答案1

得分: 1

"lubridate" 和 "hms" 包允许提取日期和时间。

一个示例:

date_time_text <- c("2023-04-28 18:04:02")

date_time <- lubridate::ymd_hms(date_time_text)
  date <- as.Date(date_time)
  time <- hms::as_hms(date_time)
英文:

The lubridate and hms packages allow extraction of dates and times.

An example:

date_time_text &lt;- c(&quot;2023-04-28 18:04:02&quot;)

date_time &lt;- lubridate::ymd_hms(date_time_text)
  date &lt;- as.Date(date_time)
  time &lt;- hms::as_hms(date_time)

huangapple
  • 本文由 发表于 2023年5月21日 22:11:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76300316.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定