[R] how to test the existence of a name in a dataframe

2004-12-07 Thread Wolfram Fischer
I wanted to test if there exists already a name (which is incidentally a substring of another name) in a dataframe. I did e.g.: data(swiss) names(swiss) [1] FertilityAgriculture Examination Education [5] Catholic Infant.Mortality ! is.null(swiss$EduX) [1]

Re: [R] how to test the existence of a name in a dataframe

2004-12-07 Thread Dimitris Rizopoulos
Hi Wolfram, this behaviour is due to partial matching. Observe that data(swiss) swiss$Ed swiss$Edu swiss$Educ I think the best way to do it is with `%in%' or `match()', i.e., c(Ed, Edu, Educ, Education) %in% names(swiss) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student