4
I have the following date.frame in R:
df <- data.frame(x = c(10,10,2,3,4,8,8,8),
y = c(5,4,6,7,8,3,2,4))
df
x y
1 10 5
2 10 4
3 2 6
4 3 7
5 4 8
6 8 3
7 8 2
8 8 4
First point: I would like to get all lines containing the 5 highest values in the column x
, can repeat.
Example:
The five largest in the column x
sane: 10, 10, 8, 8, 8.
I can get it with the following code:
rev(sort(df$x))[1:5]
[1] 10 10 8 8 8
But I’d like to take the whole row, not just the column values x
. Therefore, the result I desire is:
1 10 5
2 10 4
6 8 3
7 8 2
8 8 4
And not:
> [1] 10 10 8 8 8
If I wanted to take the repetitions? In this case, the values of the lines were 10,8,4,3,2. How would it be?
– Fillipe
I want to take all the lines that it contains in the "X" column the 10,8,4,3,2.
– Fillipe