Reputation: 358
I want to delete one max and one min values from a vector.
> x<-c( 1,1,1,3,8,9,9)
I want to get 1,1,3,8,9 as my result.
> y<-c(max(x),min(x))
> y
[1] 9 1
setdiff(x,y)
[1] 3 8
setdiff
can't work . How can i get it?
Upvotes: 0
Views: 3034
Reputation: 226182
Another possibility:
x[-c(which.min(x),which.max(x))]
(which.min()
and which.max()
identify the first occurrence of the min or max value respectively)
Upvotes: 5
Reputation: 59970
There's about a bazillion ways....
# Assuming your data is already sorted as in OP,
# here's a relatively inefficient way to do it...
head(tail(x,-1),-1)
#[1] 1 1 3 8 9
Upvotes: 3