[英]How can I use R to extract a set of 10 consecutive data where 5 out of them meet certain criteria?
I have a dataframe for a population recovery after a pesticide application.我有一个 dataframe 用于杀虫剂施用后的种群恢复。 It has two columns, the days and the recovery (0-100%).
它有两列,天数和恢复 (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%.
当 10 天中有 5 天恢复达到/大于 90% 时,我想提取第一个 10 天的时间段。 How can I do this?
我怎样才能做到这一点?
I am super new to R so this may be a simple question.我是 R 的超级新手,所以这可能是一个简单的问题。 But your help would be very much appreciated as it really helps me out.
但非常感谢您的帮助,因为它确实帮助了我。
Many thanks!非常感谢!
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))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.