I want to write a switch statement in r with three conditions but can't seem to get it to work. What am I doing wrong?
# assigning some values
test.type <- "p"
var.equal<- TRUE
paired <- FALSE
# preparing text for which p-value adjustment method was used
test.description <- switch(
EXPR = test.type & var.equal & paired,
"p" & TRUE & TRUE = "Student's t-test",
"p" & FALSE & TRUE = "Student's t-test",
"p" & TRUE & FALSE = "Student's t-test",
"p" & FALSE & FALSE = "Games-Howell test",
"np" & TRUE & TRUE = "Durbin-Conover test"
)
#> Error: <text>:10:23: unexpected '='
#> 9: EXPR = test.type & var.equal & paired,
#> 10: "p" & TRUE & TRUE =
#> ^
Created on 2018-11-08 by the reprex package (v0.2.1)
A simpler version of this statement with just one condition does work-
# simpler switch
(test.description <- switch(
EXPR = test.type,
"p" = "Student's t-test",
"np" = "Durbin-Conover test"
))
#> [1] "Student's t-test"
Created on 2018-11-08 by the reprex package (v0.2.1)