I wrote As a beginner, I agree .... the for loop is much clearer to me.
Wacek Kusnierczyk <waclaw.marcin.kusnierc...@idi.ntnu.no> replied > >well, that's quite likely. especially given that typical courses in >programming, afaik, include for looping but not necessarily functional >stuff -- are you an r beginner, or a programming beginner? > Both. My PhD is in psychometrics, and, both in course work and since then I've learned a good bit of statistics, but very little programming. I've picked up a little SAS programming over the years, but not much. But the loop (at least for me) translates into English more directly than the lapply statement does. >among the perl packages i have ever downloaded from cran, it's hard to >find one without a for loop, but it's easy to find one without a map. >but it's not necessarily because for loops are easier; just that that's >the way people are typically taught to program. > >the structure and interpretation of computer programs (sicp) by abelson >& sussman, a beautiful cs masterpiece, introduces mapping (lapplying) on >p. 105, mentions a for-each control abstraction only in an exercise two >pages later, and does not really discuss for looping as such. >functional mapping over stateless objects is, in general, *much* easier >to reason with than procedural looping over stateful objects -- an issue >a beginner may not be quite aware of, and learning the basic for loop >stuff without caring about, e.g., concurrent access to shared mutable >state etc. may indeed make the impression that for loops are easier. > >anyway, once you've learned for loops, it's not a bad idea to learn >lapply. and once you've learned lapply, you'll probably not go back to >for loops that easily. > Would that be a good book for a beginner? Peter Peter L. Flom, PhD Statistical Consultant www DOT peterflomconsulting DOT com ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.