turning off case sensitivity in r

jon picture jon · Dec 2, 2011 · Viewed 28.2k times · Source

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

Answer

Josh O&#39;Brien picture Josh O'Brien · Dec 2, 2011

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