How do I sort a dataset in R?

2 posts / 0 new
Last post
dal.don
Offline
Joined: 10/10/2011
How do I sort a dataset in R?

Hello,

I am trying to sort a data frame of approximately 1500 interviews by invite date and completion date. I see that the "sort" command isn't what I need, but I'm having a difficult time getting the "order" command to work. I've read the help page, but it is a little difficult to grasp which is the relevant example.

The code I am using is:

sorted.df <- unsorted.df[order(int.data, comp.date), ]

Any help would be appreciated.

bryan
Offline
Joined: 01/15/2009

Your code assumes that you've attached the "unsorted.df" data frame. I.e.,

attach(unsorted.df)

If you haven't done that you'll need to directly name the variables, so your code would be:

sorted.df <- unsorted.df[order(unsorted.df$int.data, unsorted.df$comp.date), ]

You might also try the orderBy() function in the "doBy" package. Once you understand the formula input you may find that format easier.

Login or register to post comments