dplyr filter function source code ,i can't get,when I click filter(), source code is UseMethod(), when I debug either.nothing appeard;
my test code :
filter(irirs,Sepal.Length>7.1)
so I try to write my own function
first version :
filter<-function(data,condition){
attach(data)
r<- data[which(condition,)]
detach(data)
return (r)
}
It works ,when I use system.time() to compared dplyr:filter and mine:filter, mine loose,spend much time than dplyr;
second version:
filter<-function(data,condition){
r<-with(data,data[which(condition),])
return (r)
}
It report errors , Sepal.Length not found.
I kwnow is condition param'problem,
if I use with(irirs,irirs[which(Sepal.Length>7.1),]) directly ,it works, but I need a own filter function
I have two question :
- a. how to write a effective filter or fix my second version code's problem.
- b. how to read function source code like usemethod("func")
thanks a lot!