If we have a data frame x:
x = data.frame(V1=c(1,2,3),V2=c(10,11,12),V3=c('a','b','c'),V4=c('x','y','z'),V5=c('l', 'm','n'), stringsAsFactors=FALSE)
where V1and V2in fact numeric, and the remaining columns are not factors, then we can do:
library(dplyr)
y <- x %>% select_if(function(col) is.numeric(col) |
all(col == .$V4) |
all(col == .$V5))
#
#
#
#
, , , , . , select_if , , .
- select:
y <- x %>% select(which(sapply(.,class)=="numeric"),V4,V5)
#
#
#
#
, , .