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
if you'd like to avoid numeric indices, you can use
a <- setdiff(names(a),c("name1", ..., "namen"))
to delete names namea...namen from a. this works for lists
namea...namen
> l <- list(a=1,b=2) > l[setdiff(names(l),"a")] $b [1] 2
as well as for vectors
> v <- c(a=1,b=2) > v[setdiff(names(v),"a")] b 2