I can't figure out a simple problem of how to call a variable name from a dataframe passed as string( function input).
I have a function defined as:
box_lambda = function(Valuename,data1){
data1[,Valuename]=ifelse(data1[,Valuename]==0,0.000001,data1[,Valuename])
b= boxcox(get(Valuename) ~ Age.Group+Sex , data = data1)
lambda <- b$x[which.max(b$y)]
return(lambda)
}
But this doesn't work as I get error:
Error in eval(f): 'list' object cannot be coerced to type 'double'
I tried
data1[[Valuename]]=ifelse(data1[Valuename]]==0,0.000001,data1[[Valuename]])
Any help is appreciated!