I am trying to create a new variable that prints the first value of a series of column, only if a certain condition is met.
To clarify, my database looks something like this:
| var1 | var2 | var3 | var4 |
|---|---|---|---|
| C7931 | C3490 | R0781 | I10 |
| R079 | R0600 | I10 | C3490 |
| S270XXA | S225XXA | C3490 | C7931 |
I want to create a variable (main) that prints the value in the first var column only if the value does not start with C00 to C99. If the value does start with that condition, then I would like to test the condition the next column, until the condition is met, and the value is printed.
Therefore, the newly created variable (main) should look something like this for the table above:
| var1 | var2 | var3 | var4 | main |
|---|---|---|---|---|
| C7931 | C3490 | R0781 | I10 | R0781 |
| R079 | R0600 | I10 | C3490 | R079 |
| C0258 | S225XXA | C3490 | C7931 | S225XXA |
I am not too sure where to start, but I suspect that maybe this might involve mutate() and ifelse()