I'm struggling with using mapply on functions I construct where I have one or more arguments that are needed because I am programming in a bigger environment, for example if I write a function where one of the arguments are data.
fun_test <- function(data,col,val1,val2){return(data[col][1,] * val1-val2)}
So data and col can for example be constant, but I want to vary the output of my function depending on val1 and val2:
> mapply(FUN=fun_test,mtcars,"cyl",mtcars$cyl,mtcars$cyl*2)
Error in data[col][1, ] : incorrect number of dimensions
I'm trying to understand how mapply works; I surely cannot pass mtcars, and "cyl" as a vector, can I?
EDIT: I have an environment in which the data may vary, e.g. sometimes I use mtcars, sometimes it is another dataset. So I cannot hardcode the data into the function
EDIT2: 1) I have data some dataset, 2) I have different Excel-files that I read into R, 3) I make a lookup function that extracts information from these Excel-files in R, 4) for one or two variables (from the dataset) at the time I go into the lookup-functions I created and extract information.
So these lookup functions depend on both the data (the variables I need to lookup) and the Excel-files that I use to do the looking up.