turning off case sensitivity in r

后端 未结 2 1242
有刺的猬
有刺的猬 2021-02-05 03:24

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)))
         


        
2条回答
  •  星月不相逢
    2021-02-05 04:12

    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
    

提交回复
热议问题