In order to filter a data.frame for only the the columns of interest I need to find the columns in this data.frame containing data outside a specific range. Let the data.frame be
df<-data.frame(x1=c(1,5,9),x2=c(10,20,30),x3=c(20,100,1000))
ranges<-data.frame(y1=c(3,8),y2=c(10,20), y3=c(15,1250))
As an output I'd like a list returning the colnames: "x1","x2"
I tried the following, but the code works only if "ranges" contains all the numbers as specified below, and matches if the number is found. Thats unfortunately not what I need.
ranges<-c(15:300,10:20)
df.l<-colnames(df)[sapply(df,function(x) any(x %in% ranges))]
Any ideas? Thanks!