Skip to content
Related Articles

Related Articles

Remove Objects from Memory in R Programming – rm() Function
  • Difficulty Level : Basic
  • Last Updated : 19 Jun, 2020
GeeksforGeeks - Summer Carnival Banner

rm() function in R Language is used to delete objects from the memory. It can be used with ls() function to delete all objects. remove() function is also similar to rm() function.

Syntax: rm(x)

Parameters:
x: Object name

Example 1:




# R Program to remove 
# objects from Memory
  
# Creating a vector
vec <- c(1, 2, 3, 4)
vec
  
# Creating a list
list1 = list("Number" = c(1, 2, 3),
             "Characters" = c("a", "b", "c"))
list1
  
# Creating a matrix
mat <- matrix(c(1:9), 3, 3)
mat
  
# Calling rm() Function
rm(list1)
  
# Calling ls() to check object list
ls()

Output:



[1] 1 2 3 4
$Number
[1] 1 2 3

$Characters
[1] "a" "b" "c"

     [, 1] [, 2] [, 3]
[1, ]    1    4    7
[2, ]    2    5    8
[3, ]    3    6    9
[1] "mat" "vec"

Example 2:




# R Program to remove 
# objects from Memory
  
# Creating a vector
vec <- c(1, 2, 3, 4)
  
# Creating a list
list1 = list("Number" = c(1, 2, 3),
             "Characters" = c("a", "b", "c"))
  
# Creating a matrix
mat <- matrix(c(1:9), 3, 3)
  
# Calling rm() Function
# to remove all objects
rm(list = ls())
  
# Calling ls() to check object list
ls()

Output:

character(0)

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :