1

I have a variable which is count_process = "time>=20" Now i want to use it in a IF condition like

if(time>=20){ do something }

How can I do that?

Sim101011
  • 305
  • 1
  • 13

1 Answers1

3

One option would be to extract the numeric substring with sub and use it in the if condition

 val <- as.numeric(sub('[^0-9]+', '', count_process))
 if(time >= val){do something}

Other option would be using eval(parse( (not recommended though)

 if(eval(parse(text=count_process))){do something}
akrun
  • 874,273
  • 37
  • 540
  • 662