user2543427
user2543427

Reputation: 133

Sorting a Data frame on R

I have a data frame, class, with 3 columns (user, lab_id, score). Some lines have the same user, and the same lab_id, and some are unique rows. I want to sort the rows to go in order of user, then lab_id and the score, where score would be going in decreasing order.

So I type:

sort.class<-class[order("class$user","class$lab_id","-class$totalScore"),]

But this just gives me a data frame with only 1 row, which I know is impossible.

Upvotes: 0

Views: 226

Answers (1)

David Robinson
David Robinson

Reputation: 78590

Don't put those arguments to order in quotes:

sort.class<-class[order(class$user,class$lab_id,-class$totalScore),]

Upvotes: 3

Related Questions