【问题标题】:How to use is.null() using brackets [] rather than the dollar sign $? [duplicate]如何使用括号 [] 而不是美元符号 $ 来使用 is.null()? [复制]
【发布时间】:2019-11-12 22:25:50
【问题描述】:

相当简单的问题。我在循环中使用 is.null() 来查看变量是否存在于许多数据帧中。

is.null(mtcars$ddd)

TRUE

这很好用。但我需要将变量插入为这样的文本:

is.null(mtcars[, c("ddd")])

Error in `[.data.frame`(mtcars, , c("ddd")) : undefined columns selected

在将变量名作为文本插入时,有什么方法可以使用 is.null() 函数?

【问题讨论】:

    标签: r dataframe null


    【解决方案1】:

    使用

    is.null(mtcars[["ddd"]])
    

    !hasName(mtcars, "ddd")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-06
      • 1970-01-01
      • 2021-07-13
      • 2011-01-04
      • 2021-09-21
      • 2019-05-22
      • 2015-06-24
      • 2019-07-18
      相关资源
      最近更新 更多