How to exclude element from a list in R

Asked

Viewed 2,457 times

11

I have this list:

x = list(1, 3, 5, 8, 13)

How do I delete the second element?

2 answers

9


Another way that serves for any R object, and not just lists, is not to select the element you want to remove and assign back to the original object:

x <- x[-2]

7

In accordance with the documentation of R, simply set null to the element you want to remove:

x[[2]] <- NULL

Browser other questions tagged

You are not signed in. Login or sign up in order to post.