I feel this is an easy solution for someone with more experience in R then myself, but I am having trouble completing the correct syntax for the following calculation.
As part of a 9 item questionnaire we use, people can respond between the ranges of 1 - 11.
For questions Q1, Q4 and Q7 if you answered between 8-11 for at least 2 of them AND for question Q3, Q6, and Q9 you answered between 8-11 for at least 2 of them you are classified into a certain category.
My question is how do you properly perform this, specifically the AND/OR option since 2 out of 3 and 3 out of 3 are both valid.
I import the csv file with 10 columns (ID, Q1, Q2....Q9)
Making a new variable at the end (i.e., categoryX) is simply. But the calculation/operator is the part I'm having an issue with.
For example I've been playing around with:
database$categoryX[(dataset$Q1 & dataset$Q4 | dataset$Q7 > 7) & (dataset$Q3 & dataset$Q6 | dataset$Q9 > 7)] <- 1
But as some of you probably already know, this doesn't work fully. I've tried || and playing around but I can't get it. Does anyone know how to handle this?
Greatly appreciate it any advice !
dat = tibble::tribble(
ID, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9
001, 9, 3, 9, 8, 3, 3, 1, 3, 10
002, 1, 11, 7, 1, 7, 7, 1, 7, 8
003, 1, 11, 11, 1, 11, 11, 7, 11, 11
004, 4, 10, 9, 9, 9, 6, 6, 8, 6
)``````