How can I remove an element from a list?

前端 未结 16 1441
傲寒
傲寒 2020-11-28 01:21

I have a list and I want to remove a single element from it. How can I do this?

I\'ve tried looking up what I think the obvious names for this function would be in

16条回答
  •  孤城傲影
    2020-11-28 01:36

    Here is how the remove the last element of a list in R:

    x <- list("a", "b", "c", "d", "e")
    x[length(x)] <- NULL
    

    If x might be a vector then you would need to create a new object:

    x <- c("a", "b", "c", "d", "e")
    x <- x[-length(x)]
    
    • Work for lists and vectors

提交回复
热议问题