The rm()
function in R is used to delete or remove a variable from a workspace.
The rm()
function takes the following syntax:
rm (…, list = character(), envir = as.environment(pos), inherits = FALSE)
The rm()
function takes the following parameter values:
...
: This represents the objects to be removed.list
: This represents a character vector that names the variables to be removed.envir
: This indicates the environment to be used.inherits
: This takes a boolean value (TRUE
or FALSE
) and determines if the closing frame of the environment should be inspected or not.# A code to illustrate the rm() function in R# creating variablesa <- 4b <- sqrt(a)c <- b * bd <- c * b# listing all the variables in the present working directoryls()# removing variablesrm(list = c("a", "d"))ls()
a
, b
, c
, and d
.ls()
function to return a list of all the variables in the workspace.rm()
function, we remove variables a
and d
.ls()
function once again, we return the list of all the variables present in the workspace.