Reputation: 56232
When working with R, one of the most common errors is using a non-existent column:
Error in `[.data.frame`(data, , c(id, nbdays, study, methods)) :
undefined columns selected
For simple code, this is easy to fix, but for complex code and dataframes having hundreds of columns, identifying the offending column can quickly become a nightmare.
Is there a way to figure out which columns are missing?
Upvotes: 1
Views: 2168
Reputation: 886938
We can do intersect
to find the intersecting columns
intersect(names(data), c("id", "nbdays", "study", "methods"))
Or with setdiff
to find the columns not be found
setdiff(names(data), c("id", "nbdays", "study", "methods"))
Upvotes: 2