Hello André,

> I want to eliminate an element of a list:
>
> list <- seq(1,5,1)

That's not a list, it's a vector

> s <- sample(list,1)
>
> lets say s=3
> Now I want to remove 3 from the list: list2 = {1,2,4,5}

If all values are unique as in your example, this will work
x <- 1:5
s <- sample(x, 1)
x <- x[ x != s ]

The last step could also be...
x <- x[ -match(s, x) ]  # note minus sign

Lots of other was to do it too.

Note, I'm assuming you won't always have values equal to the element indices.

Michael

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to