R - 如何在IF语句中测试字符(0) [英] R - How to test for character(0) in IF statement

查看:199
本文介绍了R - 如何在IF语句中测试字符(0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这非常简单,但似乎无法找到答案。

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

我正在写一个IF语句,但测试的对象是否返回 character(0) value。我不知道如何在声明中处理字符(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.

假设测试< - 字符(0)或值:

if (identical(Pols4,character(0))) {
  print('Empty')
} else {
  print('Not Empty')
}

它似乎仍然不起作用.....

It still does not seem to work.....

推荐答案

使用相同的函数进行检查。

a <- character(0)
identical(a, character(0))  # returns TRUE

identical(a, "")           # returns FALSE
identical(a, numeric(0))   # returns also FALSE

这篇关于R - 如何在IF语句中测试字符(0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆