I have a random created dataframe named a
:
group marks upd
1 a 2 up
2 b 3 up
3 a 4 down
4 b 5 up
5 a 6 down
6 c 7 up
7 a 8 down
I wanted to subset it with only group='a'
and marks in decreasing order of a
. I used this query but the marks are not arranged in decreasing order. What is the error in my code?
Here is my code and output:
> a[a$group=="a" & a$marks[order(a$marks,decreasing=T)],]
group marks upd
1 a 2 up
3 a 4 down
5 a 6 down
7 a 8 down
Warning message:
In a$group == "a" & order(a$marks, decreasing = TRUE)[1:3] :
longer object length is not a multiple of shorter object length
dplyr
when manipulating data. It is much simpler and looks more elegant :) $\endgroup$