字符串比较

基本类型 / 字符串

first <- "A"
second <- "B"
third <- "A"

are_equal1 <- first == second
# are_equal1 = FALSE

are_not_equal <- first != second
# are_not_equal = TRUE

are_equal2 <- first == third
# are_equal2 = TRUE

more_than <- first > second
# more_than = FALSE

# Ignore case
same_ignore_case <- tolower(first) == tolower("a")
# same_ignore_case = TRUE

# Text order, not numeric
text_less <- "10" < "9"
# text_less = TRUE

# identical() compares whole objects
same_vector <- identical(c("a", "b"), c("a", "b"))
# same_vector = TRUE

cat("are_equal1 =", are_equal1, "\n")
cat("are_not_equal =", are_not_equal, "\n")
cat("are_equal2 =", are_equal2, "\n")
cat("more_than =", more_than, "\n")
cat("same_ignore_case =", same_ignore_case, "\n")
cat("text_less =", text_less, "\n")
cat("same_vector =", same_vector, "\n")