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() |
chevron_right
filter_none
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() |
chevron_right
filter_none
Output:
character(0)
Recommended Posts:
- R - Creating, Listing, and Deleting Objects in Memory
- Get Exclusive Elements between Two Objects in R Programming - setdiff() Function
- Intersection of Two Objects in R Programming - intersect() Function
- Check if Two Objects are Equal in R Programming - setequal() Function
- Check for Presence of Common Elements between Objects in R Programming - is.element() Function
- Union of two Objects in R Programming - union() Function
- Get Addition of the Objects passed as Arguments in R Programming - sum() Function
- Concatenating Objects in R Programming - combine() Function
- List all the Objects present in the Current Working Directory in R Programming - ls() Function
- Looping over Objects in R Programming
- Remove Duplicate Elements from an Object in R Programming - unique() Function
- Remove names or dimnames from an Object in R Programming - unname() Function
- Remove unnecessary values from an Object in R Programming - na.omit() Function
- Getting attributes of Objects in R Language - attributes() and attr() Function
- Getting Multiplication of the Objects passed as Arguments in R Language - prod() Function
- Compare two Objects for Equality in R Progamming - identical() Function
- R - Objects
- Check if a Function is a Primitive Function in R Programming - is.primitive() Function
- Compute Density of the Distribution Function in R Programming - dunif() Function
- Apply a Function over a List of elements in R Programming - lapply() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

