1

For example let's be a vector ttt <- c(1,5,7,2,6) and suppose that we want a vector with ttt's elements bigger than 2. Then we have to write ttt[ttt>2].

Can we have a function TF_sequense(,), witch does this thing by writing TF_sequense(ttt,>2)?

I tried do.call() function from this question, but I couldn't find a solution.

Thanks in advance!

1 Answers1

1

We can use

 TF_sequence <- function(vec, expr) {
               obj1 <- deparse(substitute(vec))
               eval(parse(text = sprintf("%s[%s%s]", obj1, obj1, expr)))
  }

 TF_sequence(ttt, ">2")
akrun
  • 874,273
  • 37
  • 540
  • 662