Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R - How to re-order row index number

Simply put, I have the following data frame:

        Signal
    4   9998
    3   549
    1   18
    5   2.342
    2   0.043

and I want to reset the index numbers to be like :

        Signal
    1   9998
    2   549
    3   18
    4   2.342
    5   0.043
like image 507
mtleis Avatar asked Jun 03 '15 16:06

mtleis


People also ask

How do I reorder row numbers in R?

The dplyr function arrange() can be used to reorder (or sort) rows by one or more variables. Instead of using the function desc(), you can prepend the sorting variable by a minus sign to indicate descending order, as follow. If the data contain missing values, they will always come at the end.

How do I change the order of data in R?

To sort a data frame in R, use the order( ) function. By default, sorting is ASCENDING. Prepend the sorting variable by a minus sign to indicate DESCENDING order.

How do I index a row in R?

Use the square bracket operator with df[] notation to select rows by index in R, The syntax of this notation is df[rows, columns], replace rows with the index number, index range, or list of index values.


1 Answers

You can use

 row.names(yourdf) <- NULL

to reset the row names

like image 84
akrun Avatar answered Oct 16 '22 21:10

akrun