lapply - function with arguments

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

lapply - function with arguments

Randall Wrong
Dear R users,

I have created a function f of n, a and b : f(n,a,b)

I would like to apply this function several times to some values of n. a and
b are held constant. I was thinking of using lapply. How can I do this ?

Thank you very much
Randall

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: lapply - function with arguments

jholtman
lapply(yourList, f, a=1, b=2)

On Tue, Apr 13, 2010 at 9:11 AM, Randall Wrong <[hidden email]>wrote:

> Dear R users,
>
> I have created a function f of n, a and b : f(n,a,b)
>
> I would like to apply this function several times to some values of n. a
> and
> b are held constant. I was thinking of using lapply. How can I do this ?
>
> Thank you very much
> Randall
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>



--
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: lapply - function with arguments

Randall Wrong
Thank you Jim

2010/4/13 jim holtman <[hidden email]>

> lapply(yourList, f, a=1, b=2)
>
>   On Tue, Apr 13, 2010 at 9:11 AM, Randall Wrong <[hidden email]>wrote:
>
>>  Dear R users,
>>
>> I have created a function f of n, a and b : f(n,a,b)
>>
>> I would like to apply this function several times to some values of n. a
>> and
>> b are held constant. I was thinking of using lapply. How can I do this ?
>>
>> Thank you very much
>> Randall
>>
>>        [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
>
> --
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem that you are trying to solve?
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: lapply - function with arguments

Arun.stat
another thought possibly

fn = function(n, a=1, b=3) return(n*(a+b))
sapply(1:3, fn)