0

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.

1
  • 1
    Ultimately, these sorts of questions are really user error, and you can try to do some debugging on your own. For example, using the inbuilt dataset "mtcars", what do you get when you run order("mtcars$mpg", "mtcars$cyl", "-mtcars$disp")? Yup. 1. So if you tried to sort by that, you would be essentially doing the equivalent of mtcars[1, ], which would return a single row. Commented Jul 2, 2013 at 16:39

1 Answer 1

3

Don't put those arguments to order in quotes:

sort.class<-class[order(class$user,class$lab_id,-class$totalScore),] 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.