[英]R datetime format issues
I am currently trying to determine the time and date on the observations in my dataset. 我目前正在尝试确定数据集中观测值的时间和日期。 The date/timestamp is as follows: 1458024601.18659 1458024660.818 The observation are recorded ever minute.
日期/时间戳如下:1458024601.18659 1458024660.818观察记录每分钟记录一次。 I am trying to convert the above date/time stamp into something for understandable/ interpretable.
我正在尝试将上述日期/时间戳转换为易于理解/解释的内容。 Could you please help me with this issue.
您能帮我解决这个问题吗? Many thanks.
非常感谢。
Looks like seconds, but seconds starting from when? 看起来像秒,但秒从何时开始? Typically, 1970-01-01:
通常,1970-01-01:
> x = 1458024601.18659
> as.POSIXct(x, origin="1970-01-01")
[1] "2016-03-15 06:50:01 GMT"
So if you are expecting that timestamp to be that time, we've got the origin right. 因此,如果您希望该时间戳记为该时间,那么我们就可以正确选择原点。
If you are expecting a date in 1946, then origin="1900-01-01"
is probably what you want. 如果您希望在1946年约会,那么您可能想要
origin="1900-01-01"
。
Since, according to your most recent post, the data is stored as a factor
class, some further manipulations are required. 由于根据您最近的帖子,数据被存储为
factor
类,因此需要进行一些其他操作。
To convert the factor column into the required numeric class, this modification of @Spacedman's answer should work: 要将因子列转换为所需的数值类,对@Spacedman答案的这种修改应起作用:
as.POSIXct(as.numeric(as.character(all_prices$timestamp)), origin="1970-01-01")
Your solution is perfect, except that i have another issue :( I tried to run this code on the data.frame that i have. Unfortunately, i keep getting this following error after running the code. 您的解决方案是完美的,除了我还有另一个问题:(我试图在我拥有的data.frame上运行此代码。不幸的是,在运行代码后,我一直收到以下错误消息。
dates <- as.POSIXct(all_prices$timestamp, origin="2016-03-15") Error in as.POSIXlt.character(as.character(x), ...) : character string is not in a standard unambiguous format
date <-as.POSIXct(all_prices $ timestamp,origin =“ 2016-03-15”)as.POSIXlt.character(as.character(x),...)中的错误:字符串不是标准的明确格式
Data "all_prices" is a data.frame. 数据“ all_prices”是一个data.frame。
class(all_prices) [1] "data.frame"
class(all_prices)[1]“数据框”
data "all_prices$timestamp" is a factor. 数据“ all_prices $ timestamp”是一个因素。
class(all_prices$timestamp) [1] "factor"
class(all_prices $ timestamp)[1]“因素”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.