1

I want to sort a variable in the dataset.

la3 <-order(la1$Id)

Iam getting the output as index. How to get the output as real values in the datatset

suresh
  • 33
  • 5

2 Answers2

4
la3 <-la1[order(la1$Id),]

The length of the order will correspond to the length of the column and specify the ordered position. Using an index call of the original data will therefore put the rows in that order.

zacdav
  • 4,603
  • 2
  • 16
  • 37
0

Using dplyr

library(dplyr)
la1 %>%
    arrange(Id)
akrun
  • 874,273
  • 37
  • 540
  • 662