Remove Multiple Data Objects Using rm Function in R (Example)
In this tutorial, I’ll illustrate how to delete several data objects from the R environment running the rm function only once in the R programming language.
The content of the article looks as follows:
It’s time to dive into the exemplifying R code…
Creating Example Data
As a first step, we’ll have to construct some data that we can use in the examples below.
data <- data.frame(x1 = 1:5, # Creating data x2 = LETTERS[1:5]) vec <- 1:10 # Creating vector
The previous R code shows the structure of our example data: We have created one data frame object and a vector.
Example: Removing Data Frame & Vector Using rm() Function
This Example explains how to delete multiple data objects from the global R environment in one line of R code. Have a look at the rm() function in action:
rm(data, vec) # Apply rm()
As you have seen based on the previous R code, we simply had to insert the names of the data objects that we want to remove, separated by a comma. Have a look at your RStudio console. The data objects data and vec will not be contained in the environment anymore.
Video & Further Resources
Do you want to know more about the rm function in R? Then you may want to have a look at the following video of my YouTube channel. In the video, I illustrate the contents of this article:
The YouTube video will be added soon.
In addition, you might want to read the other RStudio tutorials on my homepage:
In this R tutorial you learned how to clean multiple data objects simultaneously. Let me know in the comments, in case you have any further questions.
Subscribe to the Statistics Globe Newsletter
Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.
Thank you!
Welcome to the Statistics Globe newsletter. From now on, I’ll send you regular emails about statistics, data science, AI, and programming with R and Python.
I’m Joachim Schork. On this website, I provide statistics tutorials as well as code in Python and R programming.
Statistics Globe Newsletter
Get regular updates on the latest tutorials, offers & news at Statistics Globe. I hate spam & you may opt out anytime: Privacy Policy.
Thank you!
Please check your email inbox and click the confirmation link to complete your subscription. If you don’t see the email within a few minutes, please also check your spam/junk folder.






