-4

I have a dataframe for a population recovery after a pesticide application. It has two columns, the days and the recovery (0-100%). I would like to extract the first period of 10 days when 5 out of the 10 days the recovery reaches/is greater than 90%. How can I do this?

I am super new to R so this may be a simple question. But your help would be very much appreciated as it really helps me out.

Many thanks!

  • As stated in the answer by @user13900375, please create a reproducible example: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – emilliman5 Aug 21 '20 at 14:31

1 Answers1

0

your question should provide a reproducible example, also wasn't clear on how the rolling average should be calculated.

here's a little bit of code that might help you:

library(dplyr)
library(zoo)
set.seed(1)
x <- data.frame(
        days = 1:100,
        recovery = runif(100,0,1)
    )
x <- x %>% mutate(av = zoo::rollmean(x$recovery > 0.9, k = 10, fill = NA))
dspn
  • 274
  • 2
  • 9
  • Hi! I have created a loop to locate the first row of the first set of 10 consecutive rows that meets the condition by using the following code: data =105 & abun$mean_data >= 0.5),] – Skylar Xie Aug 31 '20 at 14:51