0 votes
1 view
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:

data

data_1

data_2

data_3

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
by (25.3k points)

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"))

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...