R - How to test for character(0) in IF statement

后端 未结 6 1901
别那么骄傲
别那么骄傲 2020-12-14 14:36

I imagine this is incredibly simple but I cant seem to find the answer.

I am writing an IF statement but the test is if the object returns a character(0)

6条回答
  •  囚心锁ツ
    2020-12-14 14:58

    Use the identical function to check this.

    a <- character(0)
    identical(a, character(0))  # returns TRUE
    
    identical(a, "")           # returns FALSE
    identical(a, numeric(0))   # returns also FALSE
    

提交回复
热议问题