0

I would like to condition off of a range of values-- i.e. if all of the following k values are 0, then a set constant subtracts 5

for (i in 14:(nrow(data) - hold.pd - 1)){
  if (data$WaitBin[(i+1):(i+wait.pd)] == c(rep(0, wait.pd))) {
    weight == weight - 5 
  }
}

I get warnings that the condition has length > 1

joran
  • 169,992
  • 32
  • 429
  • 468
mwr
  • 31
  • 3
  • 1
    Try `if(all(data$WaitBin[(i+1):(i+wait.pd)] == 0))`. Note that on the RHS the zero recycles. – Rui Barradas Jul 08 '19 at 19:19
  • 1
    @mwr: Welcome to Stack Overflow! Could you make your problem reproducible by sharing a sample of your data so others can help (please do not use `str()`, `head()` or screenshot)? You can use the [`reprex`](https://reprex.tidyverse.org/articles/articles/magic-reprex.html) and [`datapasta`](https://cran.r-project.org/web/packages/datapasta/vignettes/how-to-datapasta.html) packages to assist you with that. See also [Help me Help you](https://speakerdeck.com/jennybc/reprex-help-me-help-you?slide=5) & [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269) – Tung Jul 09 '19 at 05:07

0 Answers0