Re: [R] rm(l*)

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Mon, 14 Jul 2008 10:59:34 +0100 (BST)

On Mon, 14 Jul 2008, Gabor Csardi wrote:

> Maybe there is a simpler way, but this works fine:
>
>> l1 <- 1
>> l2 <-2
>> m <-10
>> ls()
> [1] "l1" "l2" "m"
>> rm(list=grep("^l.*", ls(), value=TRUE))
>> ls()
> [1] "m"
>>
>
> You can supply a regular expression to grep.

And as the 'pattern' argument of ls(). So following the ls() help page

rm(list=ls(pattern=glob2rx("l*")))

>
> Gabor
>
> On Mon, Jul 14, 2008 at 10:45:13AM +0200, Oehler, Friderike (AGPP) wrote:
>> Dear Rusers,
>>
>> how can I designate various objects the names of which start (or end) with
>> the same letter to remove them all together?
>>
>> For instance:
>>> ls()
>> "a","b","c","l1","l2","x"
>>> rm(list=ls("l*"))
>>> ls()
>> "a","b","c",""x"
>>
>> Is there some parallel to the MySQL query: where col1 like "l%"
>>
>> Thanks a lot in advance,
>> Friderike
>>
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help_at_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.
>
> --
> Csardi Gabor <csardi_at_rmki.kfki.hu> UNIL DGM
>
> ______________________________________________
> R-help_at_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.
>

-- 
Brian D. Ripley,                  ripley_at_stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-help_at_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.
Received on Mon 14 Jul 2008 - 10:05:39 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 14 Jul 2008 - 10:31:45 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive