In my dataframe there is a column with "Sound" and "Response" as values. Ideally, the pattern is two Sounds followed by one Response. But, it can happen that there are three Sounds followed by a Response.
How can I tell R to raise a flag whenever it finds this pattern in my data? I need to look at each case individually before I can delete the third Sound-row.
>df <- data.frame(V1=rep("SN", 7),
V3=c("Sound", "Sound", "Response", "Sound", "Sound", "Sound", "Response"),
V4=c("XYZc02i03", "XYZq02i03", 200, "ZYXc01i30", "ZYXq01i30", "ZYXc01i35", 100),
stringsAsFactors=FALSE)
V1 V3 V4
SN Sound XYZc02i03
SN Sound XYZq02i03
SN Response 200
SN Sound ZYXc01i30
SN Sound ZYXq01i30
SN Sound ZYXc01i35
SN Response 100
So, after finding three consecutive Sounds and deleting the last one of them (i. e. the one just before the folowing Response), I should have the desired pattern like this:
V1 V3 V4
SN Sound XYZc02i03
SN Sound XYZq02i03
SN Response 200
SN Sound ZYXc01i30
SN Sound ZYXq01i30
SN Response 100
I'm sorry that I keep posting these basic questions. Any ideas are, as always, greatly appreciated!