[R] nested "for" loops

Carl Witthoft carl at witthoft.com
Sat Nov 5 18:57:31 CET 2011

If in fact this is homework, you will do yourself, your classmates, and 
possibly your teacher if you let them know that, at least in R, almost 
anything you can do in a for() loop can be done easier and faster with 
vectorization.  If you teacher can't comprehend this, get him fired.

b<- c( 9,4,1)
d <- c(4,7,2,8)

winning.value <- max(outer(a,outer(b,d,"*"),"*"))

From: R. Michael Weylandt <michael.weylandt_at_gmail.com>
Date: Sat, 05 Nov 2011 10:21:05 -0400
Why do you need to do it with nested for loops? It is of course possible 
- and I hinted how to do it in my first email - but there's no reason as 
far as I can see to do so, particularly as a means of MLE. Sounds 
suspiciously like homework...


On Nov 4, 2011, at 10:14 PM, nick_pan <nick_pan88_at_yahoo.gr> wrote:

 > Thank you , this works but I have to do it with nested for loops...
 > Could you suggest me a way ?

Sent from my Cray XK6
"Pendeo-navem mei anguillae plena est."

More information about the R-help mailing list