Peter Flom wrote: > As a beginner, I agree .... the for loop is much clearer to me. > > >> 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. >
don't really know sas, but i guess for looping is of essence there, while mapping is not. > But the loop (at least for me) translates into English more directly than the > lapply statement does. > lapply easily translates to 'apply this to every item there', which is roughly an alternative version of 'for each item in there, do this with the item'. >> >> 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. >> >> > Would that be a good book for a beginner? > both yes and no. this is a book that can be used by an absolute beginner in programming, but if you're focused on statistics, you're unlikely to enjoy it, at least not as a practical introduction. but it's a good read, and contains quite a lot of useful ideas anyway. vQ ______________________________________________ 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.