Hello I have a database of football matches for prediction.
Team<-rep("A",10)
Match<-1:10
Outcome<-c("W","W","W","L","L","W","L","W","L","L")
mymatch<-data.frame(Team,Match,Outcome)
I would like to create a column with the number of successive wins but also successive losses. When the team loses the win sequence starts again at zero. Similarly when it wins the sequence of defeat resumes at zero. I also need a column for the end of a sequence, whether it is a win or a loss.
Team Match Outcome win_seq win_end loss_seq loss_end
1 A 1 W 1 0 0 0
2 A 2 W 2 0 0 0
3 A 3 W 3 1 0 0
4 A 4 L 0 0 1 0
5 A 5 L 0 0 2 1
6 A 6 W 1 1 0 0
7 A 7 L 0 0 1 1
8 A 8 W 1 1 0 0
9 A 9 L 0 0 1 0
10 A 10 L 0 0 2 1