Search code examples
rcase-sensitive

turning off case sensitivity in r


I am having difficulty with case sensitivity. Can we turn it off?

A1 <- c("a", "A", "a", "a", "A", "A", "a")
B1 <- c(rep("a", length(A1)))

A1 == B1
# [1]  TRUE FALSE  TRUE  TRUE FALSE FALSE  TRUE

should be all TRUE


Solution

  • There's no way to turn off case sensitivity of ==, but coercing both character vectors to uppercase and then testing for equality amounts to the same thing:

    toupper(A1)
    [1] "A" "A" "A" "A" "A" "A" "A"
    
    toupper(A1)==toupper(B1)
    # [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE