Question: My data looks something like this:

```
dat <- data.frame(Model = rep(c("OM", "EM-1", "EM-2", "EM-3"), each = 3),
              Run = rep(c(1,2,3), time=4),
              Value = c(2,10,5,20,26,7,8,15,33,11,31,7))

```

Where I have values from multiple models across several runs, in this case 4 models with 3 runs each. The "OM" model is the base case and I would like to compare everything back to it.

I would like to, using tidyverse, calculate a new value which would be the difference between each model run and its corresponding "OM" model run. I think I am getting close with:

```
library(tidyverse)
 x <- dat %>%
      group_by(Run)  %>%
      filter(!is.na(Value)) %>%
      mutate(Diff = c(NA, diff(Value)))

```

Which calculates the difference between Runs of subsequent models but I cant figure out how to get all of these calculations to be in relation to the "OM" model, instead of just whatever the previous model was. I know I can do this by subsetting my data and doing the calculations that way but I am trying to do it cleanly in tidyverse since I will have lots of different models over time and don't want to have to subset all of them to run calculations.

Thanks in advance for the help.

Answer: 
Yes, your coding technique is good (or at least acceptable).

Using `break` is perfectly fine in `for` loops. In fact, it suggest you may have advanced knowledge about `Java` as you already demonstrate that you know that `break` will end the loop.

The same goes for using `return` multiple times as it demonstrates that you know that a function will stop running once it `return`s something, meaning that you know using multiple `return`s can improve efficiency.

Also, your frequent use of `for` loops demonstrates that you're comfortable using them, which is good. Your use of `i` and `j` as counter variables strengthens this impression.

Note: I would just like to point out that using lengthy variable names isn't the best practice as you're more prone to making a typo (that said, it's good that you're using camelCase for your variables).
I refactored the method into smaller methods to show you an example of what I meant in my comment. See below. Multiple `return` or `break` statements, as well as a lot of variables, all in one method, can be hard to read. By breaking the logic up into smaller pieces it's more manageable. Three steps - find the breaking element, get the new fixed array, check it and return a `boolean` based on what it looks like.

```
public boolean isAlmostIncreasing(int[] sequence) {
    int[] newFixedArray = toNewFixedArray(sequence);

    for (int i = 0; i < newFixedArray.length - 1; i++) {
        if (newFixedArray[i] >= newFixedArray[i + 1]) {
            return false;
        }
    }

    return true;
}

private int[] toNewFixedArray(int[] sequence) {
    int[] newFixedArray = new int[sequence.length
                                - 1]; /* an array used to store the edited or fixed array for further processing */

    int indexOfBreakingElement = findBreakingElementIndex(sequence);

    if (indexOfBreakingElement > 0) {                   
        for (int i = 0; i < indexOfBreakingElement; i++) {
            newFixedArray[i] = sequence[i];
        }
        for (int i = indexOfBreakingElement + 1; i < sequence.length; i++) {
            newFixedArray[i - 1] = sequence[i];
        }
    }

    for (int i = 0; i < sequence.length - 2; i++) {
        if (newFixedArray[i] >= newFixedArray[i + 1]) {
            indexOfBreakingElement = i;
            for (int j = i + 1; j < sequence.length; j++) {
                newFixedArray[j - 1] = sequence[j];
            }
            break;
        }
    }

    return newFixedArray;
}

private int findBreakingElementIndex(int[] sequence) {
    int indexOfBreakingElement = 0;

    for (int i = 0; i < sequence.length - 1; i++) {
        if (sequence[i] >= sequence[i + 1]) {
            indexOfBreakingElement = i + 1;
            break;
        }
    }

    return indexOfBreakingElement;
}

```