【问题标题】:Writing an if statement when the value can be NULL or a string当值可以是 NULL 或字符串时编写 if 语句
【发布时间】:2022-06-30 14:59:25
【问题描述】:

我有一个可以是NULL 或字符串的值。第二个测试失败,因为a 的长度为0。 我如何编写处理这两种情况的if-statement

例子:

a <- NULL
    
if (is.null(a) | a=="something else then null") {
  print("test")
} 

【问题讨论】:

    标签: r if-statement null


    【解决方案1】:

    is.null(a) || a=="something else then null"

    (类似地,在这种情况下使用&amp;&amp; 而不是&amp;

    【讨论】:

    • 我现在觉得很傻哈哈,我还以为是错误的原因失败了..谢谢!
    • 你知道为什么在这种情况下双 or 是必要的吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-21
    • 2022-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多