Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

r

What is the rm() function in R?

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The rm() function in R is used to delete or remove a variable from a workspace.

Syntax

The rm() function takes the following syntax:

rm   (…, list = character(), envir = as.environment(pos), inherits = FALSE)
Syntax for the rm() function in R

Parameters

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.

Example

# A code to illustrate the rm() function in R

# creating variables
a <- 4
b <- sqrt(a)
c <- b * b
d <- c * b

# listing all the variables in the present working directory
ls()

# removing variables
rm(list = c("a", "d"))

ls()
Implementing the rm() function in R

Explanation

  • Lines 4–7: We create variables a, b, c, and d.
  • Line 10: We call the ls() function to return a list of all the variables in the workspace.
  • Line 13: Using the rm() function, we remove variables a and d.
  • Line 15: Using the ls() function once again, we return the list of all the variables present in the workspace.

RELATED TAGS

r

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring