
Walter L. answered 11/07/19
Data Sci Grad Student Former Chem Major
#I will create the example dataframe and show code to help find if a column called "d" exists in it.
a=c(1,2)
b=c(1,2)
c=c(1,3)
example=data.frame(a,b,c)
#If you want to find whether there exists a column called "d":
"d" %in% names(example)
names() gives back the column names of a dataframe
a %in% b returns TRUE when a is an element in b. For example,
1 %in% c(1,2,3,4) returns TRUE.