Skip to content
Back to formatted view

Raw Message

Message-ID: <51521F9A.9060306@sapo.pt>
Date: 2013-03-26T22:22:18Z
From: Rui Barradas
Subject: when to use which apply function?
In-Reply-To: <CAE2FW2=EFMUL9fBAKawbxyXirdxWLBrtXs41b0bHr9KB44n+NQ@mail.gmail.com>

Hello,

The correct syntax would be


sapply(1:10, function(i) newfun(x=mat[i, 1], y=mat[i, 2], a=a, b=b))


Hope this helps,

Rui Barradas

Em 26-03-2013 21:51, C W escreveu:
> Dear list,
>
> I am a little confused as to when to use apply, sapply, tapply, vapply,
> replicate.  I've encountered this several times,
> This is time, this is what I am working on,
>
>   mat <- matrix(c(seq(from=1, to=10), rnorm(10)), ncol=2)
>
>   a=1; b=5
>
> newfun <- function(x, y, a, b)
>
> {
>
>   x*y+a+b
>
> }
>
>   sapply(i=1:10, newfun(x=mat[i, 1], y=mat[i, 2], a=a, b=b))
>
> Error in match.fun(FUN) : argument "FUN" is missing, with no default
>
> I want to use ith row of mat, evaluate newfun().  Am I making a parameter
> mistake, or should I use a different apply function?
>
>
> Thanks in a advance,
>
> Mike
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
>