Thanks Josh and Karl. function dnrm() works well for my purpose.
--
View this message in context:
http://r.789695.n4.nabble.com/How-to-remove-all-objects-except-a-few-specified-objects-tp2335651p2337398.html
Sent from the R help mailing list archive at Nabble.com.
Thanks to De-Jian and Peter. Peter's way is neat and cool!
--
View this message in context:
http://r.789695.n4.nabble.com/How-to-remove-all-objects-except-a-few-specified-objects-tp2335651p2338221.html
Sent from the R help mailing list archive at Nabble.com.
a - 1
b - 2
c - 3
ls()[-a] # set minus to all the objects you want to retain
rm(list = ls()[-a] # will remove all the objects - except a
ls() # presto
--
View this message in context:
2010/8/24 500600 romu...@gmail.com:
a - 1
b - 2
c - 3
ls()[-a] # set minus to all the objects you want to retain
rm(list = ls()[-a] # will remove all the objects - except a
ls() # presto
Only because a=1 and a is the first item in the list! Not because you
are doing '-a'! If a is 0
or use
#not checked
rm(setdiff(ls(),c(a, b))
On Aug 24, 2010, at 4:55 AM, Barry Rowlingson wrote:
2010/8/24 500600 romu...@gmail.com:
a - 1
b - 2
c - 3
ls()[-a] # set minus to all the objects you want to retain
rm(list = ls()[-a] # will remove all the objects - except a
ls() # presto
If you are going to be doing this a lot, you may want to consider
making a little function. Here is an example 'do not remove'
function. It defaults to the global environment, but you can always
change it. Also, if you try to keep a variable name that does not
exist, it will throw an error and
Thanks for all suggestions from Roman (?= 500600[via R]), Barry and Jim.
It seems that ls()[-objectname] didn't work even on numeric matrices and
user made functions. I will work with Jim's advice on using grep() and gc()
to see whether it works.
--
View this message in context:
Hi Cheng,
Check out the keep() function in package:gdata.
And to be sure the removed objects are really removed from system
memory i think you need to run gc().
hth,
Karl
On 8/23/2010 9:00 PM, Cheng Peng wrote:
How to remove all R objects in the RAM except for a few specified ones?
If your specified objects have a certain pattern, you can use the
parameter pattern in ls() to remove or keep it.
rm(list=ls(..., pattern=your_pattern))
If not, possibly you have to manually specify them.
On 2010-8-24 3:00, Cheng Peng wrote:
How to remove all R objects in the RAM except for a
ls(all=TRUE).
HTH
Peter Alspach
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
project.org] On Behalf Of Dejian Zhao
Sent: Wednesday, 25 August 2010 1:32 p.m.
To: r-help@r-project.org
Subject: Re: [R] How to remove all objects except a few
How to remove all R objects in the RAM except for a few specified ones?
rm(list=ls()) removes all R objects in the R work space.
Another question is that whether removing all R objects actually releases
the RAM? Thanks.
--
View this message in context:
11 matches
Mail list logo