R - 如何在 IF 语句中测试字符(0) [英] R - How to test for character(0) in IF statement
本文介绍了R - 如何在 IF 语句中测试字符(0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想这非常简单,但我似乎找不到答案.
I imagine this is incredibly simple but I cant seem to find the answer.
我正在编写 IF 语句,但测试的是对象是否返回 character(0)
值.我不知道如何处理语句中的 character(0)
.
I am writing an IF statement but the test is if the object returns a character(0)
value. I am not sure how to deal with character(0)
in the statement.
假设 Test <- character(0)
或一个值:
if (identical(Pols4,character(0))) {
print('Empty')
} else {
print('Not Empty')
}
好像还是不行.....
It still does not seem to work.....
推荐答案
使用 identical
函数来检查这个.
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
这篇关于R - 如何在 IF 语句中测试字符(0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文