0

I have a test datafile

enter image description here

I would like to run a t test.

This will work, which I already know

t.test(df_test$clin_value ~ df_test$trt_variable)

But I would like to do this:

trt_var = "trt_variable"

noquote(trt_var) # which gives me trt_variable

why I can not run this?

t.test(df_test$clin_value ~ df_test$(noquote(trt_var)))

How can I make this work?

I have to do this way, because I would like to change trt_var constantly.

MrFlick
  • 195,160
  • 17
  • 277
  • 295
cautree
  • 35
  • 7
  • `noquote()` just doesn't print quotes around the string in the console. It doesn't have magic powers to create a variable name unfortunately. You cannot use `$` with variable values. Instead use `[[ ]]`. Something like `t.test(df_test$clin_value ~ df_test[[trt_var]])` should work. – MrFlick Feb 07 '20 at 19:52
  • Thanks, it is solved, I tried [] previously, but not [[]]. – cautree Feb 07 '20 at 20:03

0 Answers0