s-news
[Top] [All Lists]

Re: apply functions on several objects all at once.

To: Steve Su <s.su@qut.edu.au>
Subject: Re: apply functions on several objects all at once.
From: Patrick Burns <pburns@pburns.seanet.com>
Date: Wed, 16 Apr 2003 11:06:41 +0000
Cc: s-news@lists.biostat.wustl.edu
References: <000c01c303fc$06515020$2032b583@busaccb337f>
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01
One of my current tasks has a similar problem where I just want to see
the results of the function.  I do something analogous to:

for(i in objects(pat='Apple.field')) print(myfun(get(i)))


It slightly complicates things if you want to assign the results.  I would
do:

obj.in <- ls(pat="Apple.field")
obj.out <- paste(obj.in, "out", sep=".")
for(i in seq(along=obj.in)) assign(obj.out[i], myfun(get(obj.in[i])))


Patrick Burns

Burns Statistics
patrick@burns-stat.com
+44 (0) 208 525 0696
http://www.burns-stat.com/    (new home of S Poetry)
(and "A Guide for the Unwilling S User")


Steve Su wrote:

Dear All,

Is it possible to apply a function on several objects all at once?

I have a list of objects with names like Apple.field.1 Apple.field.2
--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu.  To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message:  unsubscribe s-news





<Prev in Thread] Current Thread [Next in Thread>