[R] Is there an variant of apply() that does not return anything?

Peng Yu pengyu.ut at gmail.com
Thu Nov 19 23:31:35 CET 2009

On Thu, Nov 19, 2009 at 4:27 PM, Marc Schwartz <marc_schwartz at me.com> wrote:
> On Nov 20, 2009, at 10:21 AM, Peng Yu wrote:
>> There are a few version of apply() (e.g., lapply(), sapply()). I'm
>> wondering if there is one that does not return anything but just
>> silently apply a function to the list argument.
>> For example, the plot function is applied to each element in 'alist'.
>> It is redundant to return anything from apply.
>> apply(alist,function(x){ plot each element of alist})
> Just use a for() loop. If you are plotting things, the performance
> bottleneck is not going to be in the loop.
> Sometimes, we get too anal about avoiding for() loops.

Is there a way to get the name of the list in the loop body?

> List=list(a='c',b='x',e='q')
> for(x in List) { print(x) }
[1] "c"
[1] "x"
[1] "q"

More information about the R-help mailing list