Hallo, i have an SPSS syntax which worked in SPSS perfectly. For further Regression Models I changed to R Studio now, but I didn't manage until now to convert the SPSS Syntax into an RScrpit. Maybe someone can help me here. My task is, I have the Variable CTQ_EM, which I want to convert into CTQ_EM_SG, and this variable should have the value 1 if it is <8, value 2 if it is between 9-12, value 3 between 13-15, and value 4 >= 16.
So here is the original SPSS Syntax:
IF (CTQ_EM <= 8) CTQ_EM_SG=0.
EXECUTE.
IF(CTQ_EM >=9) CTQ_EM_SG=1
EXECUTE.
IF (CTQ_EM >= 13) CTQ_EM_SG=2.
EXECUTE.
IF (CTQ_EM >= 16) CTQ_EM_SG=3.
EXECUTE.
i have tried different codes, but none of them have worked yet, maybe someone has an idea ?thank you very much in advance!
1)
Df %>% mutate(CTQ_emo_abuse_SG=case_when(Df,CTQ_emo_abuse <= 8 ~ '1', between(CTQ_emo_abuse, 9, 12) ~ '2', between(CTQ_emo_abuse, 13, 15) ~ '3', CTQ_emo_abuse >=16 ~ 4))
—>Error in mutate()
:
In argument:
CTQ_emo_abuse_SG = case_when(...)
.
Caused by error in case_when()
:
! Failed to evaluate the left-hand side of formula 1.
Caused by error:
! object 'CTQ_emo_abuse' not found
- Df <- mutate (Df, CTQ_emo_abuse_SG = case_when(Df$CTQ_emo_abuse <= 8 ~ 1,Df$CTQ_emo_abuse >=9 ~ 2, Df$CTQ_emo_abuse >=13 ~ 3, Df$CTQ_emo_abuse >=16 ~ 4))
—> CTQ_emo_abuse_SG
must be size 209 or 1, not 0.