检查在8天内的每个ID的观察次数
在下面的数据集中,我想知道每个 ID
在 8 天的块中有多少个观察值。解决这个问题的最佳方法是什么?
library(lubridate)
library(tidyverse)
date <- rep_len(seq(dmy("01-01-2013"), dmy("31-12-2013"), by = "days"), 300)
ID <- rep(c("A","B","C"), 50)
deer <- data.frame(date = date,
utm_x = runif(length(date), min = 238785, max = 453354.5),
utm_y = runif(length(date), min = 4096853.0 , max = 4280487.1 ),
ID)
deer$julian <- yday(as.Date(deer$date))
deer$month <- month(deer$date)
deer$year <- year(deer$date)
我已经能够获取每个 ID
的观察总数,但我不确定如何查看数据集中每个 ID 在每 8 天的时间内有多少观察结果:
# Observation Distribution
count <- data.frame(table(df$AnimalID))
colnames(count)[1] <- "ID"
In the data set below, I would like to know how many observations each ID
has in 8 day chunks. What would be the best way to approach this?
library(lubridate)
library(tidyverse)
date <- rep_len(seq(dmy("01-01-2013"), dmy("31-12-2013"), by = "days"), 300)
ID <- rep(c("A","B","C"), 50)
deer <- data.frame(date = date,
utm_x = runif(length(date), min = 238785, max = 453354.5),
utm_y = runif(length(date), min = 4096853.0 , max = 4280487.1 ),
ID)
deer$julian <- yday(as.Date(deer$date))
deer$month <- month(deer$date)
deer$year <- year(deer$date)
I have been able to get the total number of observations for each ID
, but I'm unsure on how to see how many observations each ID has within each 8 day period in the data set:
# Observation Distribution
count <- data.frame(table(df$AnimalID))
colnames(count)[1] <- "ID"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们可以使用
ceiling_date
创建一个分组变量,然后使用n()
获取count
或summarise
We may create a grouping variable with
ceiling_date
and then get thecount
orsummarise
withn()