giegie
giegie

Reputation: 463

Remove specific data frame from a list of data frames in R

I have a large list of dataframes. I would like to remove one specific dataframe e.g. d2 in this example.

my.list
$d1
  y1 y2
1  1  4
2  2  5
3  3  6

$d2
  y1 y2
1  3  6
2  2  5
3  1  4

Upvotes: 3

Views: 7557

Answers (2)

Gregor Thomas
Gregor Thomas

Reputation: 145835

A few options:

# assign it to NULL
my.list$d2 = NULL
my.list[["d2"]] = NULL

# remove second item
my.list = my.list[-2]

# subset by  name
my.list = my.list[names(my.list) != "d2"]

Upvotes: 8

stoa
stoa

Reputation: 93

This will drop the second element from the list.

my.list = my.list[-2] 

Upvotes: 4

Related Questions