You can try exists():
exists("Unknown Value")
[1] FALSE
Unknown Value <- 42
exists("Unknown value")
[1] TRUE
Or you can also do it using data a frame method:
Let's create a data frame first :
data <- data.frame(z1 = c(2, 8, 8, 1, 1), # Create example data.frame
z2 = c(6, 7, 1, 3, 1)) //We are creating 2 data frames
If there's a need to check for the existence of particular column names in the data frame above we need to attach the data frame first using:
attach(data) # This will Attach data.frame
and after this check the existence of variable names in the data, using:
exists("z1") # Apply exists to variable of data
# TRUE
z1 exists:
exists("z3") # Apply exists to non-existent variable
# FALSE
but Z3 doesn't exist.
after this detach the data as it can lead to confusion in the following programming steps:
detach(data) # This will Detach data.frame