I would like to add a number to only MATH in column course based on the following condition; for each ID if MATH has output column equal to pass increase the attached number by 1 for the next MATH. here is an example:
df = read.table(text =
'ID course outcome
10 MATH fail
10 PHYS pass
10 MATH pass
10 MATH fail
10 CHEM pass
11 MATH pass
11 PHYS fail
12 CMP pass
12 MATH fail
12 MATH fail
12 CHEM pass
12 MATH pass
12 MATH fail', header = T)
df_result = read.table(text =
'ID course outcome
10 MATH1 fail
10 PHYS pass
10 MATH1 pass
10 MATH2 fail
10 CHEM pass
11 MATH1 pass
11 PHYS fail
12 CMP pass
12 MATH1 fail
12 MATH1 fail
12 CHEM pass
12 MATH1 pass
12 MATH2 fail', header = T)
Please help me to do it in R