I have data like these:
A1 A2 A3 A4 B C1 C2 C3 C4
1 3 2 2 7 2 NA 6 9
4 6 12 1 3 1 6 5 2
6 1 NA 1 7 3 2 2 1
I want to take the maximum value of the columns starting with "C" and then subtract the "A" column ending with the same number from "B". For example, the max of the "C"s in the first row would be 9 and so I would want to subtract A4 from B (7-2)
A1 A2 A3 A4 B C1 C2 C3 C4 new
1 11 2 2 7 2 NA 6 9 5
4 6 12 1 3 1 6 5 2 -3
6 1 NA 1 7 3 2 2 1 1
Is this possible? Maybe using "starts_with"?