r - Using a global function to identify which subfunctions to run -


i have dataset categorical variable may take around 6 or 7 unique variables. depending upon variable is, need run several functions - each of different depending upon value of categorical variable.

i don't know how go programming things called correctly. keep in mind might simple here, in scenario more complicated lots of sub functions.

    library(dplyr)     func1_value_one = function(multiplication_value){     mtcars$check="value_one"     mtcars$mpg =mtcars*multiplication_value     filter(mtcars, mpg>60)       }     func0_value_zero = function(division_value){     mtcars$check="value_zero"     mtcars$mpg =mtcars$mpg / division_value     filter(mtcars, mpg <3)       }          help_function=function(category_p,change_p){         mtcars=return(filter(mtcars, vs==category_p))             data=ifelse(category_p==0,return(func0_value_zero(change_p)),return(func1_value_            one(change_p)  ))         return(data)          }   #i want filter values meet parameter passed in , perform update on values  # right not able both filter values , perform correct function call.         help_function(0,2) 

so identifying_func(0,20) return only rows mtcars has vs==0, divide mpg values 20, , create new column called check values equal 'value_zero'

in broader context, dataset use flag determine many different table join combinations , depending upon data perform variety of calculations , adjustments.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -