I have a large dataset which I want remove all the rows except for the first 8 per value of 1 variable. (in this example only the first one)
example set:
Time <- c(1:20)
stimulus <- c(rep("happy 1",4),rep("happy 2",4),rep("disgust 1",4),rep("anger 1",4),rep("sad 1",4))
Happy <- c(runif(20,0,1))
Disgust <- c(runif(20,0,1))
Anger <- c(runif(20,0,1))
Subj1<- data.frame(Time,stimulus,Happy,Disgust,Anger)
SO: I want to remove all rows except for Subj1$stimulus 1st row of "happy 1", "happy 2", "disgust 1" etc. I manage to do so by subsetting to a new variable and then de-selecting everything but the first 8 rows using the following code:
Stim1<-which(Subj1$stimulus=="happy 1")
Subj1<- Subj1[-c(Stim1[2:length(Stim1)]),]
However, I want to automatically run this for all stimulus variables. Another thing that makes this more difficult is that the row numbers jump because of the removal of rows.