Message-ID: <CAM_vjumZ781d9k3Ck4gEtfiquJN354pWie1WyAjzqUEejs2nRA@mail.gmail.com>
Date: 2011-11-14T16:42:21Z
From: Sarah Goslee
Subject: Very simple loop
In-Reply-To: <1321286354611-4039895.post@n4.nabble.com>
Hi,
On Mon, Nov 14, 2011 at 10:59 AM, Davg <davidgrimsey at hotmail.com> wrote:
> I'm very new to R and am trying to create my first loop.
>
> I have:
>
> x <-c(0:200)
> A <- dpois(x,exp(4.5355343))
> B <- dpois(x,exp(4.5355343 + 0.0118638))
> C <- dpois(x,exp(4.5355343 ?-0.0234615))
> D <- dpois(x,exp(4.5355343 + 0.0316557))
> E <- dpois(x,exp(4.5355343 + 0.0004716))
> F <- dpois(x,exp(4.5355343 + 0.056437))
> G <- dpois(x,exp(4.5355343 + 0.1225822))
>
> and would like to to get A[K] + B[K] + C[K] + D[K] + E[K] + F[K] G[K]
> for K(0:200)
R indexing starts with 1, so even though x starts with 0, the corresponding
index is 1:201
You don't need a loop at all: R can easily handle this with:
all.sum <- A + B + C + D + E + F + G
> And then plot these cumulative values.
What kind of plot? You might check out
?hist
and
?plot
for ideas.
Sarah
--
Sarah Goslee
http://www.functionaldiversity.org