I have data on egg_number
per day per breeding pair (Parents
). I am trying to determine the average amount of time (in days) between the appearance of eggs, grouped by Parents, from the below data "egg_output1".
So basically the average difference between row dates, grouped by parents, after the data is ordered chronologically. Is this possible??
Tank Parents date egg_number
1: P3-T25 DON_AGEM_031FXDON_AGEM_036M 2017-06-03 2
2: P3-T25 DON_AGEM_031FXDON_AGEM_036M 2017-06-03 1
3: P3-T25 DON_AGEM_031FXDON_AGEM_036M 2017-05-23 1
I have tried using the following code:
as.Date(egg_output1$date)
egg <- egg_output1[order(egg_output1$date),]
ddply(
egg,
c("Parents"),
summarize,
average = mean(diff(date))
)
But this returns NA
with the following warnings:
Warning messages:
1: In mean.default(diff(date)) : argument is not numeric or logical: returning NA
2: In mean.default(diff(date)) : argument is not numeric or logical: returning NA
3: In mean.default(diff(date)) : argument is not numeric or logical: returning NA
sample data:
eggs <- data.frame(
parents = sample(c("005Fx001M", "008Fx006M","028Fx026M"), 10, replace = TRUE),
date = sample(seq(as.Date('2016/01/01'), as.Date('2017/01/01'), by="day"), 10),
egg_number = sample(c("1", "2"), 10, replace = TRUE))