mardi 21 novembre 2017

Incomplete for loop with two if-statements

I've been searching for quite some time on this site now and haven't been able to find the answer to my question.

I'm researching the correlation between several properties of a brook which are all collected in one data frame (PEQTfXS_GrooteMolenbeek). At the moment I'm concentrating at the discharge (PEQTfXS_GrooteMolenbeen$Q) of this brook. What I want to to do is run a for loop through the discharge data and assign the color red if the current value is smaller than the previous value. The color blue will be assigned if the current value is larger than the previous value. In the end, I would like to create a plot of the red and blue data points against the time (PEQTfXS_GrooteMolenbeek$date) if possible.

The loop I have right now is as follows:

for (i in 1:length(PEQTfXS_GrooteMolenbeek$Q){
if PEQTfXS_GrooteMolenbeek$Q[i] < PEQTfXS_GrooteMolenbeek$Q[i-1] col = "red"
if PEQTfXS_GrooteMolenbeek$Q[i] > PEQTfXS_GrooteMolenbeek$Q[i-1] col = "blue"
}

There seem to be a few things missing from this loop but I don't know what. Besides that, I'm wondering how I can implement the plotting part of my question.

Hopefully this question isn't too stupid. I know there are more easy ways than a for loop but I'm not interested in those ;)

Thanks!

Aucun commentaire:

Enregistrer un commentaire