删除除函数以外的所有变量 [英] remove all variables except functions
本文介绍了删除除函数以外的所有变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在R控制台中加载了不同类型的对象。
我可以使用
I have loaded in a R console different type of objects. I can remove them all using
rm(list=ls())
或使用
rm(list=lsf.str())
我的问题是:
可以删除除函数以外的所有变量
My question is: is there a way to remove all variables except the functions
推荐答案
这里是删除所有对象的单行除了函数:
Here's a one-liner that removes all objects except for functions:
rm(list = setdiff(ls(), lsf.str()))
它使用 setdiff
查找子集全局环境中没有模式 function
的对象(由 ls()
返回)通过 lsf.str()
)
It uses setdiff
to find the subset of objects in the global environment (as returned by ls()
) that don't have mode function
(as returned by lsf.str()
)
这篇关于删除除函数以外的所有变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文