如何在几个月内分发价值? #r

发布于 2025-01-31 22:27:55 字数 428 浏览 4 评论 0原文

当前,我的数据有一个用于start_date的columne,并且列为end_date。

对于每个时间段(起始末端),侧面A和侧面b的死亡人数众多。我想在几个月中分配这些值。

有时,它在同一个月和年份开始并结束(假设2020年3月),如果Deyts_a为10,那么我想在2020年3月有10个

。有时,它开始在三月开始,并于4月结束。如果Deaths_a是10岁,那么我想在3月有5个,四月的5个。

我应该如何处理?

谢谢你!

Currently, my data has a columne for start_date and a column for end_date.

For each time period (start-end), there are values like number of deaths of side a and side b. I want to divide the values across months.

Sometimes, it started and ended in the same month and year (let's say March 2020), and if deaths_a is 10, then I want to have 10 for March 2020.

Sometimes, it started in let's say March and ended in April. If deaths_a is 10, then I want to have 5 for March and 5 for April.

How should I approach this?

Thank you!

My current data has year_month

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灯下孤影 2025-02-07 22:27:55

使用橄榄酸软件包将解决。假设您总是有时间的时间顺序。

library(lubridate)

##input
date_start = "1995-03-30"
date_end = "1995-04-01"
death_a = 80

year_diff = year(ymd(date_end)) - year(ymd(date_start))
month_diff = month(ymd(date_end)) - month(ymd(date_start))
death_distri_month = death_a / (year_diff*12 + month_diff + 1 )  # 40


由于我们假设时间序列增加,因此也适用于负面的“月_diff”。

##input
date_start = "1995-09-30"
date_end = "1996-01-01"
death_a = 80

year_diff = year(ymd(date_end)) - year(ymd(date_start))
month_diff = month(ymd(date_end)) - month(ymd(date_start))
death_distri_month = death_a / (year_diff*12 + month_diff + 1 )  # 16 

Using Lubridate package will solve. Assume you always have increasing order of time.

library(lubridate)

##input
date_start = "1995-03-30"
date_end = "1995-04-01"
death_a = 80

year_diff = year(ymd(date_end)) - year(ymd(date_start))
month_diff = month(ymd(date_end)) - month(ymd(date_start))
death_distri_month = death_a / (year_diff*12 + month_diff + 1 )  # 40


Also works for negative "month_diff" since we assume an increasing sequence of time.

##input
date_start = "1995-09-30"
date_end = "1996-01-01"
death_a = 80

year_diff = year(ymd(date_end)) - year(ymd(date_start))
month_diff = month(ymd(date_end)) - month(ymd(date_start))
death_distri_month = death_a / (year_diff*12 + month_diff + 1 )  # 16 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文