Skip to content
Prev 206771 / 398506 Next

Odp: For loops in R

Hi

r-help-bounces at r-project.org napsal dne 19.01.2010 02:32:45:
for
AFAICS it seems to do what you want. Basically your rmat and rmat2 will 
have different numbers from uniform distribution. If you wanted different 
distribution of random numbers you need to use differend random number 
generator. See ?rnorm.

And repetition means that in your index you can have some rows more times 
and some rows never. Again only you know if this is desired behaviour. If 
not use replace=FALSE.
In some quite recent R-News (I believe 2009 or 2008) there is an article 
about loops. And also R-Inferno by P.Burns is worth reading.

My opinion is that simple cycles and apply functions are more or less 
similar. When I want to scan a file and make same plots for each column I 
use for cycle and in most other cases I use *apply family. If you have 
nested cycles which work correctly in reasonable time why not use them. 
But usually vectorised approach can be far quicker and, when you get used 
to it, clearer.

Regards
Petr
http://n4.nabble.com/For-loops-in-R-tp1015933p1017196.html
http://www.R-project.org/posting-guide.html