如何从单独的日期字段创建一个datetime对象? [英] How to create a datetime object from separate date fields?
本文介绍了如何从单独的日期字段创建一个datetime对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的数据集:
I have a dataset like this:
Year MM DD HH
158 2010 7 1 5
159 2010 7 1 5
160 2010 7 1 6
161 2010 7 1 6
structure(list(Year = c(2010L, 2010L, 2010L, 2010L), MM = c(7L,
7L, 7L, 7L), DD = c(1L, 1L, 1L, 1L), HH = c(5L, 5L, 6L, 6L)), .Names = c("Year",
"MM", "DD", "HH"), row.names = 158:161, class = "data.frame")
如何从此数据集(此数据的新列)创建一个datetime对象?
How can I create a one datetime object from this data set (new column for this data)?
推荐答案
有几个选项,这里有一个(其中 x
是你的data.frame):
There are a few options, here's one (where x
is your data.frame):
x$datetime <- ISOdatetime(x$Year, x$MM, x$DD, x$HH, 0, 0)
如果需要,您可以传入正确的时区,请参阅?ISOdatetime
。
You can pass in the correct time zone if need be, see ?ISOdatetime
.
这篇关于如何从单独的日期字段创建一个datetime对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文