xxxxxxxxxx
library(dplyr)
## initial dataframe
df <- data.frame(
test.type = c("p", "p", "p", "p", "np", "np"),
var.equal = c(TRUE, FALSE, TRUE, FALSE, TRUE, FALSE),
paired = c(TRUE, TRUE, FALSE, FALSE, TRUE, FALSE)
)
## add column test.description
mutate(df,
test.description = case_when(
test.type == "p" & !var.equal & !paired ~ "Games-Howell test",
test.type == "p" ~ "Student's t-test",
test.type == "np" & var.equal & paired ~ "Durbin-Conover test",
TRUE ~ "Unknown combination"
)
)
xxxxxxxxxx
# Following is val1 simple R program
# to demonstrate syntax of switch.
# Mathematical calculation
val1 = 6
val2 = 7
val3 = "s"
result = switch(
val3,
"a"= cat("Addition =", val1 + val2),
"d"= cat("Subtraction =", val1 - val2),
"r"= cat("Division = ", val1 / val2),
"s"= cat("Multiplication =", val1 * val2),
"m"= cat("Modulus =", val1 %% val2),
"p"= cat("Power =", val1 ^ val2)
)
print(result)