计算一列日期计数

发布于 2025-02-11 06:37:03 字数 293 浏览 0 评论 0原文

我想计算人们拥有的日期(或访问)数量(或访问)的平均值和标准偏差。示例数据为:

id   date
1    2015-02-23
1    2015-04-24
2    2018-05-23
2    2022-12-05
2    2022-12-06
3    2021-05-21

ID1有2次访问(由2个日期证明),ID2有3次访问,ID3有1次访问,因此平均值为(2+3+1)/3 = 2。

有人知道如何计算平均值和标准偏差吗?我尝试使用总结函数来执行此操作,但我无法正常工作。

I want to calculate the mean and standard deviation for the number of dates (or visits) that people have. Sample data are:

id   date
1    2015-02-23
1    2015-04-24
2    2018-05-23
2    2022-12-05
2    2022-12-06
3    2021-05-21

ID1 has 2 visits (evidenced by 2 dates), ID2 has 3 visits, and ID3 has 1 visit, so the mean would be (2+3+1)/3 =2.

Does anyone know how to calculate the mean and standard deviation? I tried to do this using the summarize function, but I can't get it to work.

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

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

发布评论

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

评论(1

梦里寻她 2025-02-18 06:37:03

您可以使用rle函数与ID

  • 数据
df < - structure(list(id = c(1L, 1L, 2L, 2L, 2L, 3L), date = c("2015-02-23", 
"2015-04-24", "2018-05-23", "2022-12-05", "2022-12-06", "2021-05-21"
)), class = "data.frame", row.names = c(NA, -6L))
mean(rle(df$id)$lengths)

You can use rle function with your id

  • data
df < - structure(list(id = c(1L, 1L, 2L, 2L, 2L, 3L), date = c("2015-02-23", 
"2015-04-24", "2018-05-23", "2022-12-05", "2022-12-06", "2021-05-21"
)), class = "data.frame", row.names = c(NA, -6L))
mean(rle(df$id)$lengths)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文