Data:
(actual data is way larger, but I just present here a representation for the sake of clarity)
I have the following vectors
Response <- c('blue', 'yellow', 'red', 'yellow', 'blue', 'red', 'red', 'blue', 'yellow', 'green', 'yellow', 'yellow', 'green')
ZN <- c('C', 'B', 'A','C', 'B', 'A', 'C', 'B', 'A', 'B', 'A', 'B', 'A')
Stimuli <- c('e','e','e','e','e','e','e','e','e','c','c','c','c')
Organized in this data frame:
test <- data.frame(Response, ZN, Stimuli)
Explanation: stimuli "e" had three levels (C;B;A) and stimuli "c" two levels (B;A). Participants could assign certain colours to these levels.
Goal: to contabilize for stimuli "e" how many times participants choose colour blue, red, or yellow in each level (C, B, A), e.g., in the example, blue was chosen 2 times for level C, and yellow once). An the same for stimuli "c" which has two levels (B, A).
One (cumbersome) way of doing it is by summing the number of blues when ZN =='C' and Stimuli == e
sum(data$Response == 'blue' | data$ZN =='C' | data$Stimuli == e)
Then do this for colours yellow and red (the only possible ones for stimuli "e"). And then replicate this procedure for ZN =='B' and ZN =='A'.
There must be a smarter way of doing this.. I'm just new to R, sorry if the question is too silly. In the end, the information I want to have is the following:
Stimuli e
ZN = C
2 blue
1 yellow
ZN = B
2 yellow
1 red
ZN = A
2 red
1 yellow
Thank you!