Skip to content
Back to formatted view

Raw Message

Message-ID: <4FFE83AC.8040703@stats.ox.ac.uk>
Date: 2012-07-12T07:58:36Z
From: Brian Ripley
Subject: apply() to a function that has more than 2 arguments
In-Reply-To: <1342073426180-4636257.post@n4.nabble.com>

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