Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 当你期待约会时,当你得到一个像40182或15368这样的数字时该怎么办?_R_Excel_Date - Fatal编程技术网

R 当你期待约会时,当你得到一个像40182或15368这样的数字时该怎么办?

R 当你期待约会时,当你得到一个像40182或15368这样的数字时该怎么办?,r,excel,date,R,Excel,Date,在某些情况下,您正在处理日期,突然得到的数字看起来像40182或15368。例如,从Excel导入数据时可能会发生这种情况,但在R中的操作中遇到的值也会发生这种情况。这些值如下所示: date1 <- 40182 date2 <- 15368 # the value comes from Excel as.Date(40182,origin="1899-12-30") # the value comes from R but put in number format as.Dat

在某些情况下,您正在处理日期,突然得到的数字看起来像40182或15368。例如,从Excel导入数据时可能会发生这种情况,但在R中的操作中遇到的值也会发生这种情况。这些值如下所示:

date1 <- 40182
date2 <- 15368
# the value comes from Excel
as.Date(40182,origin="1899-12-30")

# the value comes from R but put in number format
as.Date(15368,origin="1970-01-01")

date1这是有效的日期值,但来源可能不清楚。在上述情况下,您可以按以下方式转换日期:

date1 <- 40182
date2 <- 15368
# the value comes from Excel
as.Date(40182,origin="1899-12-30")

# the value comes from R but put in number format
as.Date(15368,origin="1970-01-01")

下面答案中的猜测很好,但我不介意更多的上下文。猜测数据是可怕的。(编辑:我知道你已经回答了你自己的问题。这很好,但我仍然认为这个问题需要更多的上下文以便对其他人有用…)这不是个人维基。@BenBolker,正如你所建议的,我已经添加了一点上下文。我花了一些时间寻找答案,当我找到它时,我想我也可以分享它。希望其他人能利用这次问答。