I am trying to explore the response change patterns for particular questions. Here is an example of dataset.
id <- c(1,1,1, 2,2,2, 3,3,3,3, 4,4)
item.id <- c(1,1,1, 1,1,1 ,1,1,2,2, 1,1)
sequence <- c(1,2,3, 1,2,3, 1,2,1,2, 1,2)
score <- c(0,0,0, 0,0,1, 0,1,0,0, 1,0)
data <- data.frame("id"=id, "item.id"=item.id, "sequence"=sequence, "score"=score)
data
id item.id sequence score
1 1 1 1 0
2 1 1 2 0
3 1 1 3 0
4 2 1 1 0
5 2 1 2 0
6 2 1 3 1
7 3 1 1 0
8 3 1 2 1
9 3 2 1 0
10 3 2 2 0
11 4 1 1 1
12 4 1 2 0
id
represents persons, item.id
is for questions. sequence
is for the attempt to change the response, and the score
is the score of the item.
What I am trying to observe is to subset those whose score
were changed from 0 to 1
and 1 to 0
.
The desired outputs would be:
data.0.to.1
id item.id sequence score
2 1 1 0
2 1 2 0
2 1 3 1
3 1 1 0
3 1 2 1
data.1.to.0
id item.id sequence score
4 1 1 1
4 1 2 0
Any thoughts? Thanks!