Re: [R] Puzzled by an error with apply()

2009-04-07 Thread Tony Plate

One simple explanation for the error message you received is that you have a 
typo: 'lapply' instead of 'apply':


x - matrix(1:6, 2)
apply(x, 1, sum)

[1]  9 12

lapply(x, 1, sum)

Error in match.fun(FUN) : '1' is not a function, character or symbol




However, it's difficult to diagnose without at least seeing some cut'n'pasted 
transcripts.  The output of traceback() would also be useful.

-- Tony Plate

Gang Chen wrote:

I've written a function, myFunc, that works fine with myFunc(data,
...), but when I use apply() to run it with an array of data

apply(myArray, 1, myFunc, ...)

I get a strange error:

Error in match.fun(FUN) : '1' is not a function, character or symbol

which really puzzles me because '1' is meant to be the margin of the
array I want to apply over, but how come does apply() treat it as a
function?

I have been successfully using apply() for a while, so I must have
made a stupid mistake this time. Hopefully somebody can point out
something obviously wrong without me providing any details of the
function.

TIA,
Gang

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Puzzled by an error with apply()

2009-04-06 Thread Gang Chen
I've written a function, myFunc, that works fine with myFunc(data,
...), but when I use apply() to run it with an array of data

apply(myArray, 1, myFunc, ...)

I get a strange error:

Error in match.fun(FUN) : '1' is not a function, character or symbol

which really puzzles me because '1' is meant to be the margin of the
array I want to apply over, but how come does apply() treat it as a
function?

I have been successfully using apply() for a while, so I must have
made a stupid mistake this time. Hopefully somebody can point out
something obviously wrong without me providing any details of the
function.

TIA,
Gang

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Puzzled by an error with apply()

2009-04-06 Thread Rolf Turner


On 7/04/2009, at 2:04 PM, Gang Chen wrote:


I've written a function, myFunc, that works fine with myFunc(data,
...), but when I use apply() to run it with an array of data

apply(myArray, 1, myFunc, ...)

I get a strange error:

Error in match.fun(FUN) : '1' is not a function, character or symbol

which really puzzles me because '1' is meant to be the margin of the
array I want to apply over, but how come does apply() treat it as a
function?

I have been successfully using apply() for a while, so I must have
made a stupid mistake this time. Hopefully somebody can point out
something obviously wrong without me providing any details of the
function.


If you want any help you will have to give a reproducible example.

Have you tried traceback()?

Have you tried making a local copy of apply() and putting in a call
to browser()?

Have you tried using debug()?

Sheesh!

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.