- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
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.
Example
< 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() [1] "a"
To remove all except x and a
> rm(list=ls()[! ls() %in% c("x","a")]) ls() [1] "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 blank objects from an Object in JavaScript?
- 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?

Advertisements