0

I am currently trying to automate a process that seems simple, but I have to repeat the process 800 times. I have 2 datasets, each with 8 columns. One column is streamflow, and the other is a list of thresholds (each row has a different threshold). I want to know the number of days that the streamflow falls below the threshold. So far I've done this using mutate and ifelse.

lf1 <- Daily_average_Q %>%
           mutate(lf1 = ifelse(Q1B < Thresholds$B1[1], '1', '0')

This gives me what I want for 1 threshold, but I have 100 thresholds that I need to use. I also need to do this over 8 sites, so I can't afford to do this 800 separate times. I just want the row number in Thresholds$B1[row#] to change automatically each time. I've tried looping with "for" but I can't figure out how to mutate and loop at the same time.

Thanks so much for any help!!

alistaire
  • 42,459
  • 4
  • 77
  • 117
emmab
  • 1
  • 1
    Hi emmab, welcome to so, if you could please provide a reprex of your data, else it is really hard to answer the question – Bruno Jun 08 '20 at 03:09
  • Please have a look [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) to know how to make a R reproducible example, so that other users can help you – Ric S Jun 08 '20 at 07:23

0 Answers0