Dimitris.Kapetanakis
2012-Jul-12 06:10 UTC
[R] apply() to a function that has more than 2 arguments
Dear all, I created a function which it has many arguments i.e. Mu(x, Y, B, X, P) where Mu is the function. This function works perfect but when I am trying to use it in the apply() function in the manner apply(Matr, 1, Mu, Y=y, B=b, X=x, P=p) it does not work and the output is: Error in match.fun(FUN) : '1' is not a function, character or symbol When I transform the function Mu to have less arguments like Mu(x, DATA) and use apply by apply(Matr, 1, Mu, DATA=data) it works perfect Does anyone knows where is my mistake? Thanks Dimitris -- View this message in context: http://r.789695.n4.nabble.com/apply-to-a-function-that-has-more-than-2-arguments-tp4636257.html Sent from the R help mailing list archive at Nabble.com.
Prof Brian Ripley
2012-Jul-12 07:58 UTC
[R] apply() to a function that has more than 2 arguments
On 12/07/2012 07:10, Dimitris.Kapetanakis wrote:> Dear all, > > I created a function which it has many arguments i.e. Mu(x, Y, B, X, P) > where Mu is the function. This function works perfect but when I am trying > to use it in the apply() function in the manner apply(Matr, 1, Mu, Y=y, B=b, > X=x, P=p) it does not work and the output is: Error in match.fun(FUN) : '1' > is not a function, character or symbol > > When I transform the function Mu to have less arguments like Mu(x, DATA) and > use apply by apply(Matr, 1, Mu, DATA=data) it works perfect > > Does anyone knows where is my mistake?The arguments of apply are > args(apply) function (X, MARGIN, FUN, ...) so you actually called apply(X=x, MARGIN=Matr, FUN=1, Y=y, B=b, P=p)> > Thanks > > Dimitris-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Reasonably Related Threads
- apply (or similar preferred) for multiple columns
- integrate (error: evaluation of function gave a result of wrong length)
- Question about assigning values in a matrix, conditional on column first row; how to do the loop.
- Error occurred during mean calculation of a column of a data frame, which is apparently contents numeric data
- glm (probit/logit) optimizer