names(f.list) <- paste("ff", 1:3, sep=".")
f.list[[ 3 ]](3) # 6 = 3^2 - 1 - 2
f.list[[ "ff.3" ]](3) # the same
f.list$ff.3(3) # the same
Hope this helps,
Rui Barradas
Em 23-05-2012 11:00, "R. Michael Weylandt"
escreveu:
Date: Tue, 22 May 2012 18:5
quot;
escreveu:
Date: Tue, 22 May 2012 18:50:08 -0400
From: "R. Michael Weylandt"
To: Etienne Larriv?e-Hardy
Cc:r-help@r-project.org
Subject: Re: [R] Creating functions with a loop.
Message-ID:
Content-Type: text/plain; charset=ISO-8859-1
You can do what you want with th
You can do what you want with the get() and assign() functions, though
it might be easier and better to use match.fun() than get()
Much better though would be to build your functions in a list and call
the n-th element of the list with syntax like
f.list[[3]](4)
will call the function in the thi
Michael's method seems to be working but I still can't get to wrap it in a
loop since I cannot get the loop to dynamically change the functions' name,
i.e. ff1, ff2, ff3, ... In other words, I would need the first iteration to
create the function ff1, the second to create the function ff2, ...
Furt
Interpreting your question slightly differently, where ff.k(x) is a
function call.
Suppose you want to get a list of functions like
x^2
x^2 -1
x^2 - 3
x^2 - 6
It's perfectly possible with something like this:
NextFunc <- function(f, i) {
# Takes in a function f and returns
# a different f
On May 22, 2012, at 10:06 AM, Etienne Larrivée-Hardy wrote:
Hi
I am trying to create n functions where each function is defined in
function one step before, i.e. something like
ff.k(x) = ff.j(x) - sum(1:j), for j=k-1
There is a cumsum function:
> cumsum(1:10)
[1] 1 3 6 10 15 21
Hi
I am trying to create n functions where each function is defined in function
one step before, i.e. something like
ff.k(x) = ff.j(x) - sum(1:j), for j=k-1
Is it possible? If it isn't and I manually create each function then is their a
way to call them through a loop? My objective is to
7 matches
Mail list logo