I have this dataframe (but very big that includes many rows in the name variable that hold the values yes and no)
df = data.frame(name = c('a','b','c',NA,NA,'yes','no',NA,NA,'f','g','h'),
Freq = c(10,20,70,NA,NA,40,60,NA,NA,80,10,10) )
# output
name Freq
1 a 10
2 b 20
3 c 70
4 <NA> NA
5 <NA> NA
6 yes 40
7 no 60
8 <NA> NA
9 <NA> NA
10 f 80
11 g 10
12 h 10
For every two consective rows that include yes and no in the name column, I wish them to be flipped to become as follows :
# output
name Freq
1 a 10
2 b 20
3 c 70
4 <NA> NA
5 <NA> NA
6 no 60
7 yes 40
8 <NA> NA
9 <NA> NA
10 f 80
11 g 10
12 h 10
Appreciate the help