lundi 7 août 2017

R if statement in a function with a fomula argument

testing<-function(formula=NULL,data=NULL){
  if(with(data,formula)==T){
print('YESSSS')
  }
}
A<-matrix(1:16,4,4)
colnames(A)<-c('x','y','z','gg')

testing(data=A,formula=(2*x+y==Z))
##or I can put formula=(x=1)
##reason that I use formula is because my dataset had different location and I would want
##to 'subset' my data into different set 

This is the main flow of my code. I had done some search and seems to be no one ask this kind of stupid question or it is not possible to pass a formula in a if statement. Thank you in advance

Aucun commentaire:

Enregistrer un commentaire