Message-ID: <7C2A0F3D-CEC4-4D62-A9CB-30664E5AB6AD@comcast.net>
Date: 2012-05-22T15:08:20Z
From: David Winsemius
Subject: Creating functions with a loop.
In-Reply-To: <7375FB3B53851F4DA6F2285131365A6B4E42D3AE4B@EXCH-MBX-B.ulaval.ca>
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 28 36 45 55
Did you mean something like?:
ff.k[j] <- ff.j[j] - sum(1:j), for j=k-1
In R the paren, "(", indicates that you are calling a function whereas
you appear interested in making an indexed assignment to a vector.
>
> 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
> calculate something like
>
> result.k = ff.k(x1)/ff.k(x2) for k in 2:n
You may have clear idea about which k-indices should go where in that
expression, but I surely do not. What are 'x1' and 'x2'?
--
David Winsemius, MD
West Hartford, CT