Explore Courses Blog Tutorials Interview Questions
0 votes
in R Programming by (5.3k points)

I would like to remove some data from the workspace. I know the "Clear All" button will remove all data. However, I would like to remove just certain data.

For example, I have these data frames in the data section:





I would like to remove data_1, data_2, and data_3 while keeping data.

I tried data_1 <- data_2 <- data_3 <- NULL, which does remove the data (I think), but still keeps it in the workspace area, so it is not fully what I would like to do.

1 Answer

0 votes

You can use rm or remove to remove objects. These can be specified successively as character strings, or in the character vector list, or through a combination of both. All objects thus specified will be removed.

The basic syntax is given below:

remove(..., list = character(), pos = -1, envir = as.environment(pos), inherits = FALSE) rm (..., list = character(), pos = -1, envir = as.environment(pos), inherits = FALSE)

In your case:

rm(data_1, data_2, data_3)

This will only remove data frames ‘data_1’, ‘data_2’, and ‘data_3’ from the workspace.

To remove a whole set of named-alike objects:

rm(list = ls(pattern = "data"))

This will remove all objects whose name begins with the string "data".

Similarly using remove:

remove(list=c("data_1", "data_2", "data_3"))

Related questions

+1 vote
2 answers
0 votes
1 answer
asked Jul 6, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers


94.1k users

Browse Categories