[R] apply() to a function that has more than 2 arguments

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Jul 12 09:58:36 CEST 2012


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



More information about the R-help mailing list