Re: [R] wildcards and removing variables

From: Johan Sandblom <jsandblom_at_gmail.com>
Date: Tue 11 Oct 2005 - 00:59:42 EST

rm() can take a list of object names as an argument and ls(pattern='^results') gives such a list. So

rm(ls(pattern='^results'))

would remove all objects that are matched by the regular expression, that is all that begin with 'results'

HTH, Johan

2005/10/10, Marc Schwartz (via MN) <mschwartz@mn.rr.com>:
> On Mon, 2005-10-10 at 10:37 -0400, Afshartous, David wrote:
> > All,
> >
> > Is there are a wildcard in R for varible names as in unix? For example,
> >
> > rm(results*)
> >
> > to remove all variable or function names that begin w/ "results"?
> >
> > cheers,
> > Dave
> > ps - please respond directly to afshar@miami.edu
>
>
> See ?ls, which has a 'pattern' argument, enabling the use of Regex to
> define the objects to be listed and subsequently removed using rm().
>
> You can then use something like:
>
> rm(list = ls(pattern = "\\bresults."))
>
> HTH,
>
> Marc Schwartz
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

--
Johan Sandblom  N8, MRC, Karolinska sjh
t +46851776108  17176 Stockholm
m +46735521477  Sweden
"What is wanted is not the will to believe, but the
will to find out, which is the exact opposite"
- Bertrand Russell

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Tue Oct 11 01:04:53 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 18:37:28 EST