Explore Courses Blog Tutorials Interview Questions
0 votes
in R Programming by (3.4k points)

I tried this, which failed Error: object 'ppcc' not found

is.finite(ppcc) Error: object 'ppcc' not found

1 Answer

0 votes
by (46k points)

You can try exists():

exists("Unknown Value")    


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


z1 exists:

exists("z3")        # Apply exists to non-existent variable


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

Happy Learning...!!

Related questions

+1 vote
1 answer
+1 vote
1 answer
+1 vote
1 answer

Browse Categories