R中的日期序列跨越公元前到公元 [英] Date sequence in R spanning B.C.E. to A.D

查看:64
本文介绍了R中的日期序列跨越公元前到公元的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想生成一个公元前10,000年的日期序列。到现在。对于0 CE(或AD)来说,这很容易:

I would like to generate a sequence of dates from 10,000 B.C.E. to the present. This is easy for 0 C.E. (or A.D.):

ADtoNow <- seq.Date(from = as.Date("0/1/1"), to = Sys.Date(), by = "day")

但是我对如何生成0 AD 之前的日期感到困惑。显然,我可以做很多年,但是能够以BCE和AD的形式绘制图形会很好。

But I am stumped as to how to generate dates before 0 AD. Obviously, I could do years before present but it would be nice to be able to graph something as BCE and AD.

推荐答案

To扩展里卡多的建议,这里是一些如何工作的测试。

To expand on Ricardo's suggestion, here is some testing of how things work. Or don't work for that matter.

我将重复约书亚从 as.Date 发出的警告,以粗体显示给以后的搜索者字母:

I will repeat Joshua's warning taken from ?as.Date for future searchers in big bold letters:

as.integer(as.Date("0/1/1"))
[1] -719528

as.integer(seq(as.Date("0/1/1"),length=2,by="-10000 years"))
[1]  -719528 -4371953

seq(as.Date(-4371953,origin="1970-01-01"),Sys.Date(),by="1000 years")
# nonsense
 [1] "0000-01-01" "'000-01-01" "(000-01-01" ")000-01-01" "*000-01-01"
 [6] "+000-01-01" ",000-01-01" "-000-01-01" ".000-01-01" "/000-01-01"
[11] "0000-01-01" "1000-01-01" "2000-01-01"

> as.integer(seq(as.Date(-4371953,origin="1970-01-01"),Sys.Date(),by="1000 years"))
# also possibly nonsense
 [1] -4371953 -4006710 -3641468 -3276225 -2910983 -2545740 -2180498 -1815255
 [9] -1450013 -1084770  -719528  -354285    10957

尽管这似乎确实适用于某些绘图:

Though this does seem to work for graphing somewhat:

yrs1000 <- seq(as.Date(-4371953,origin="1970-01-01"),Sys.Date(),by="1000 years")
plot(yrs1000,rep(1,length(yrs1000)),axes=FALSE,ann=FALSE)
box()
axis(2)
axis(1,at=yrs1000,labels=c(paste(seq(10000,1000,by=-1000),"BC",sep=""),"0AD","1000AD","2000AD"))
title(xlab="Year",ylab="Value")

这篇关于R中的日期序列跨越公元前到公元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆