Skip to content
Prev 313099 / 398506 Next

function to filter identical data.fames using less than (<) and greater than (>)

Hello,

Something like this?


func <- function(data, A, B, C){
     f <- function(a)
         function(x) eval(parse(text = paste("x", a)))
     iA <- if(is.na(A)) TRUE else f(A)(data$A)
     iB <- if(is.na(B)) TRUE else f(B)(data$B)
     iC <- if(is.na(C)) TRUE else f(C)(data$C)
     data[iA & iB & iC, ]
}

func(eg, "> 0", NA, NA)
func(data=eg, A="< 0", B="< 1", C="> 0")


Hope this helps,

Rui Barradas
Em 06-12-2012 13:49, Karl Brand escreveu: