简体   繁体   English

如何使用 R 提取一组 10 个连续数据,其中 5 个满足特定条件?

[英]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.

相关问题 在R中:如何将符合特定条件的值设置为特定值 - In R: How do I set values that meet a certain criteria to a certain value 如何在 R 中删除满足某些特定条件的行 - How to remove rows that meet certain certain criteria in R 如何在R中满足特定条件时获得连续出现的平均值 - How to get the average of consecutive occurrences when meet certain condition in R 选择满足R中某些条件的行 - Selecting rows that meet certain criteria in R 仅提取符合 R 中所有标准的记录:代码在示例数据上按预期工作,但在实际数据上却没有 - Extract only records that meet ALL criteria in R: code worked as expected on sample data but not on real data R:如果值满足特定条件,如何将数据框转换为邻接矩阵? - R: How do I transform a data frame into an adjacency matrix if values meet a certain condition? 如何根据R中的某些条件删除数据 - How to delete data according to certain criteria in R R:如何编写一个函数来对特定的列值求和并在满足特定条件时报告行号? - R: How to write a function to do summation of a particular column values and report the row numbers when it meet certain criteria? 根据特定标准提取数据 - Extract data according to certain criteria 在 R 中选择满足特定条件的特定行和以下行 - Selecting specific rows and following ones which meet certain criteria in R
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM