0

Fairly simple question. I am using is.null() in a loop to see if variables exist within many data frames.

is.null(mtcars$ddd)

TRUE

This works fine. But I need to insert the variables as text like this:

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

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

Is there any way to use the is.null() function while inserting the variable name as text?

Marco Pastor Mayo
  • 803
  • 11
  • 25

1 Answers1

4

Use

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

or

!hasName(mtcars, "ddd")
MrFlick
  • 195,160
  • 17
  • 277
  • 295