- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to remove all objects except one or few in R?
We can use rm remove all or few objects.
< x>-rnorm(100,0.5) < y>-1:100 < z>-rpois(100,5) < a>-rep(1:5,20)
To remove all objects
> rm(list=ls()) ls() character(0)
To remove all except a
> rm(list=setdiff(ls(), "a")) > ls()  "a"
To remove all except x and a
> rm(list=ls()[! ls() %in% c("x","a")]) ls()  "a" "x"
- Related Articles
- How to get list of all columns except one or more columns from an R data frame?
- How can I remove all elements except the first one using jQuery?
- How to remove first few rows from each group in R?
- How to select all columns except one in a Pandas DataFrame?
- How to remove last few rows from an R data frame?
- Display all records except one in MySQL
- C++ Program to Remove all Characters in a String Except Alphabets
- How to remove all documents from a collection except a single document in MongoDB?
- Python - Remove all characters except letters and numbers
- How to remove all rows having NA in R?
- Move all files except one on Linux
- Java program to remove all numbers in a string except "1" and "2"?
- Remove all except the first character of a string in MySQL?
- How to select all rows from a table except the last one in MySQL?