[R] Beginner problem - using mod function to print odd numbers
m|n@h@|| @end|ng |rom um|ch@edu
Wed Jun 9 05:28:34 CEST 2021
> Two of R's central features as a "data science" language are that many of
> its core capabilities are "vectorized" -- can calculate on whole objects
> (at the user-visible interpreter level) rather than requiring explicit
> loops; and that it can use object indexing in several different modalities,
> here logical indexing, for extraction and replacement in whole objects such
> as vectors and matrices. Not only does this typically yield simpler, more
> readable code (admittedly, a subjective judgment), but it is also typically
> much faster, though I grant you that this can often be overrated.
i sort of wanted to circle back to this.
i learned FORTRAN IV in 1968 (and the last FORTRAN program i wrote was
at least 50 years ago), and i *still* write FORTRAN code, even when
writing lisp, or R, or awk scripts. it's *very* hard for me to adapt to
so, for that reason, i think it is very useful to help people understand
and adjust to R's vector operations.
maybe a way to say it might be "here is how you will get better
performance, using R's vector operations..." and, then, "however, if you
find it simpler, and the performance acceptable, you could do a 'for'
loop like this...". (though, as this is all volunteer effort, one
obviously takes what one gets.) but, i do think that helping newer
users understand how to write efficient code is important.
anyway, just my two cents.
More information about the R-help