[R] replacing ugly for loops
gunter.berton at gene.com
Thu Oct 11 23:26:56 CEST 2012
I hate to decline such praise, but honesty demands that I must.
In fact, my solution is **not** fully vectorized at all! The tapply()
and mapply() calls are, in fact, in some sense hidden loops at the
interpreted levels. They do have the virtue of being true to R's
functional paradigm, but they are loops, nevertheless. For this
reason, they may not be more efficient then the explicit loops you've
written. But I hope the code is more transparent.
AndI did send a follow-up note to the list both acknowledging my
erroneous accusation that you did not provide data and confirming that
my proposed solution worked with the example you did, in fact,
But thanks for the kind words anyway.
On Thu, Oct 11, 2012 at 2:16 PM, andrewH <ahoerner at rprogress.org> wrote:
> Dear Bert--
> I tried your function on the data that I provided (data.df) and it worked
> beautifully (after I added a missing final parenthesis), producing exactly
> the same output as my function. This is an excellent example of what I was
> looking for, because it is
> (a) 50% shorter than mine,
> (b) fully vectorized, and
> (c) uses three functions that I have never used before: with, unique, and
> I am going to spend a happy afternoon working through this command by
> command and at the end I am confident that I will have learned some valuable
> new ( to me) tricks.
> Warmest Regards, AndrewH
> View this message in context: http://r.789695.n4.nabble.com/replacing-ugly-for-loops-tp4645821p4645914.html
> Sent from the R help mailing list archive at Nabble.com.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Genentech Nonclinical Biostatistics
Internal Contact Info:
More information about the R-help