英文:
Create normal distribution of dates in r
问题
以下是你要翻译的代码部分:
myvec <- seq(as.Date('2022/01/01'), as.Date('2023/01/01'), by='day')
sample(myvec, size=339, replace=TRUE, prob=c(0.2, 0.2, rep(0.1/337, 337)))
英文:
I'm trying to generate a distribution of dates from the vector "myvec," but my code isn't correctly working. Any suggest to create a code to generate normal distribution for 339 dates? Your assistance would be greatly appreciated.
myvec <- seq(as.Date('2022/01/01'), as.Date('2023/01/01'), by="day")
sample(myvec, size = 339, replace = TRUE,
prob = c(0.2, 0.2, rep(0.1/337, 337))
)
答案1
得分: 3
如果您想要一个接近正态分布的数据,请使用 rnorm
。
# 围绕 2022-01-01 中心的 339 个日期,标准差为 10 天。
as.Date("2022-01-01") + round(rnorm(339, mean = 0, sd = 10))
英文:
If you want a normal-ish distribution use rnorm
.
# 339 dates centered around 2022-01-01 with a sd of 10 days.
as.Date("2022-01-01") + round(rnorm(339, mean = 0, sd = 10))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论