Skip to content
Prev 275225 / 398506 Next

R for loop stops after 4 iterations

That's fantastic, thank you very much, the qnorm option is interesting, I
will have to play around with it.

Many thanks again
Philip

-----Original Message-----
From: R. Michael Weylandt [mailto:michael.weylandt at gmail.com] 
Sent: Sunday, 23 October 2011 10:28 AM
To: Philip Robinson
Cc: r-help at r-project.org
Subject: Re: [R] R for loop stops after 4 iterations

There's a seeming inconsistency in this question -- namely,  you provide an
example of a data frame with 4 columns but say it is 27x3
-- but I think your question comes from a misunderstanding of what
length(e) calculates. For a data frame it gives the number of columns back.
Hence if you have a 27x4 data frame (which you appear to) iterations will
only fill the first four elements of output.

You'd probably rather use NROW(e). As an aside, for these sort of loops,
seq_along() is usually a very good choice, but it doesn't work here because
of the length() thing.

On another note, why don't you just do the calculation analytically and save
yourself some trouble?


# Something like
with(e, qnorm(0.42, V2, V3)*100)


Michael


On Sat, Oct 22, 2011 at 7:33 PM, Philip Robinson
<philip.c.robinson at gmail.com> wrote:
this: