【发布时间】:2020-12-21 09:41:09
【问题描述】:
我有一个带有儒略日期格式的数据框:
2455764.833333
2455764.875000
2455764.916667
dput <- structure(list(date = structure(c(2L, 1L, 1L, 1L, 1L), .Label = c("",
"2011-07-21T20:00:00"), class = "factor"), longitude = structure(c(1L,
1L, 1L, 1L, 1L), .Label = "-6.396", class = "factor"), latitude = structure(c(1L,
1L, 1L, 1L, 1L), .Label = "56.6283", class = "factor"), julian = structure(1:5, .Label = c("2455764.833333",
"2455764.875000", "2455764.916667", "2455764.958333", "2455765.000000"
), class = "factor"), record_no = 1:5, temp = structure(c(1L,
3L, 2L, 4L, 5L), .Label = c("12.414", "12.463", "12.515", "12.618",
"12.767"), class = "factor"), depth = structure(c(1L, 1L, 1L,
1L, 1L), .Label = " 34.00", class = "factor")), row.names = c(NA,
5L), class = "data.frame")
在线 Julian 日期转换器可以正确转换(上面是 2011 年 7 月 22 日)-但除了日期之外,我还需要小数点后详细信息中的时间元素。
起源于公元前 4713 年 1 月 1 日。我读过 as.Date 不处理 BC 日期。如果我将 $julian 转换为数字,它会删除小数点后的数据。
我从这里尝试了各种建议,但没有找到任何适用于 BC 原点和时间元素的建议。
tiree$date2 <- as.Date(tiree$julian, origin = structure(-2440588, class = "Date"))
来自Convert Julian Date to Date - R 给我 charToDate(x) 中的错误:字符串不是标准的明确格式(编辑:根据转换为数字的建议,错误已删除但输出不正确)。
欢迎任何建议 - 我想我可能遗漏了一些明显的东西!
非常感谢
【问题讨论】:
-
试试
tiree$date2 <- as.Date(as.numeric(tiree$julian), origin = structure(-2440588, class = "Date")) -
感谢@Ronak Shah - 它确实解决了明确的格式错误,但遗憾的是,这种方法并没有给出正确的日期/时间元素。
-
请提供
dput(head(tiree$julian))。 -
已编辑添加 dput
-
@Bun 干得好,在这里共享数据时必须始终使用
dput,这样我们才能看到您的数据结构。您可以在这里了解更多信息:how-to-make-a-great-r-reproducible-example
标签: r julian-date