0 votes
1 view
in R Programming by (6.5k points)

I have loaded in an R console different type of objects. I can remove them all using

rm(list=ls())

or remove only the functions (but not the variables) using

rm(list=lsf.str())

My question is: is there a way to remove all variables except the functions

1 Answer

0 votes
by (25.3k points)

In this case, you can use the setdiff function to remove all variables except functions as follows:

rm(list = setdiff(ls(), lsf.str())) 

ls() returns the set of objects in the global environment.

lsf.str() returns the set of objects having mode function.

And,

setdiff() is used to find the subset of objects in the global environment not having mode as function.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...