Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R - how to re-order data frame by row index number

This may be a very basic question but I could't find it. Let's say I have a data frame d with row numbers in disorder like this:

    Signal
4   9998
3   549
1   18
5   2.342
2   0.043

How can I sort this by increasing row index numbers to obtain the following?

    Signal
1   18
2   0.043
3   549
4   9998
5   2.342
like image 696
biohazard Avatar asked Mar 18 '14 08:03

biohazard


People also ask

How do you set an index in a Dataframe in R?

In order to lead a dataframe with the index ID column, we can also reassign the row names of the dataframe to reflect the increasing integer values starting from 1 to the number of rows in the data frame. The rownames(df) method is used to assign the row names. All the changes are reflected in the original dataframe.


1 Answers

rownames(d) <- 1 : length(rownames(d))
like image 51
Yohanes Lie Avatar answered Nov 15 '22 17:11

Yohanes Lie