How do I sort a dataset in R?

R programming language resources Forums Data manipulation How do I sort a dataset in R?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #432
    dal.don
    Member

    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.

    #434
    bryan
    Participant

    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.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Scroll to top
Privacy Policy