write a function that takes string arguments with quotes

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

write a function that takes string arguments with quotes

onyourmark2012
I want to be able to call the function below with something like this
conditional_prob_bool(Class=='democrat',V1=='y',df)

and have
consequent_bool=df$Class=='democrat'
and
antecedent_bool=df$V1=='y'
inside the function body.

But it does not seem to work the way I want, possibly because of the quote marks. Can someone suggest how I can change the code so that I can get these assignments?

conditional_prob_bool=function(spec1,spec2,df){
 
  consequent_bool=df$spec1
  consequent_event=df[consequent_bool,]

  antecedent_bool=df$spec2
  antecedent_event=df[antecedent_bool,]

  return(prob(intersect_event(consequent_event,antecedent_event,df),df)/prob(antecedent_event,df))
}

Thank you.