How to exclude element from a list in R

10

I have this list:

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

How do I delete the second element?

    
asked by anonymous 17.06.2016 / 04:04

2 answers

9

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

x <- x[-2]
    
17.06.2016 / 14:57
7

According to documentation of R , just assign null to the element you want to remove:

x[[2]] <- NULL
    
17.06.2016 / 04:04